Leviathan87
New Member
- Joined
- Mar 2, 2022
- Messages
- 4
- Office Version
- 2013
- Platform
- Windows
Hi everyone!
I'm trying to add excel table to word!
Everything is fine but the table append on the last page of word doc.
I want to add the table in the middle of word page after some text: "then new line after that table then text again." I'm trying with replace but it doesn't work.
Do you have any idea?
This is my code!
Sub exceltoword()
Dim OutLookApp As Object
Dim OutLookMail As Object
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim Source As String
Dim wbbase As String
Dim WBname As String
Dim lastRw As Integer
Dim wdtable As Word.table
WBname = ThisWorkbook.Name
Source = "Name"
Set wdApp = CreateObject("word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open("")
With wdDoc.Content.Find
.Text = "<Name>"
.Replacement.Text = InputBox("Give me some input")
.Replacement.Font.Bold = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Set WB3 = Workbooks.Open(Source)
Worksheets("Input").Activate
Worksheets("Input").Range("C8").Select
With wdDoc.Content.Find
.Text = "<Amount>"
.Replacement.Text = Worksheets("Input").Range("C8").Value
.Replacement.Font.Bold = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Worksheets("Input").Select
Worksheets("Input").Range("C25").Select
With wdDoc.Content.Find
.Text = "<Number>"
.Replacement.Text = Worksheets("Input").Range("C25").Value
.Replacement.Font.Bold = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Worksheets("Name").Activate
lastRw = Worksheets("Input").Range("C20").Value + 3
myDoc = Worksheets("Name").Range("B3:D" & StartDate).Copy
wdDoc.Range.Characters.Last.PasteExcelTable False, True, True
Set wdtable = wdDoc.Tables(1)
wdtable.AutoFitBehavior (wdAutoFitWindow)
wdtable.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
Application.DisplayAlerts = True
wdDoc.SaveAs ""
wdDoc.Close savechanges:=True
wdApp.Quit
Set wdApp = Nothing
End Sub
I'm trying to add excel table to word!
Everything is fine but the table append on the last page of word doc.
I want to add the table in the middle of word page after some text: "then new line after that table then text again." I'm trying with replace but it doesn't work.
Do you have any idea?
This is my code!
Sub exceltoword()
Dim OutLookApp As Object
Dim OutLookMail As Object
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim Source As String
Dim wbbase As String
Dim WBname As String
Dim lastRw As Integer
Dim wdtable As Word.table
WBname = ThisWorkbook.Name
Source = "Name"
Set wdApp = CreateObject("word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open("")
With wdDoc.Content.Find
.Text = "<Name>"
.Replacement.Text = InputBox("Give me some input")
.Replacement.Font.Bold = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Set WB3 = Workbooks.Open(Source)
Worksheets("Input").Activate
Worksheets("Input").Range("C8").Select
With wdDoc.Content.Find
.Text = "<Amount>"
.Replacement.Text = Worksheets("Input").Range("C8").Value
.Replacement.Font.Bold = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Worksheets("Input").Select
Worksheets("Input").Range("C25").Select
With wdDoc.Content.Find
.Text = "<Number>"
.Replacement.Text = Worksheets("Input").Range("C25").Value
.Replacement.Font.Bold = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Worksheets("Name").Activate
lastRw = Worksheets("Input").Range("C20").Value + 3
myDoc = Worksheets("Name").Range("B3:D" & StartDate).Copy
wdDoc.Range.Characters.Last.PasteExcelTable False, True, True
Set wdtable = wdDoc.Tables(1)
wdtable.AutoFitBehavior (wdAutoFitWindow)
wdtable.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
Application.DisplayAlerts = True
wdDoc.SaveAs ""
wdDoc.Close savechanges:=True
wdApp.Quit
Set wdApp = Nothing
End Sub