Add table from excel to the middle side of word doc after specific text

Leviathan87

New Member
Joined
Mar 2, 2022
Messages
4
Office Version
  1. 2013
Platform
  1. 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
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,214,596
Messages
6,120,438
Members
448,966
Latest member
DannyC96

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top