Insert text from Excel into word document - after bookmark

Sarahmueller

New Member
Joined
May 17, 2020
Messages
24
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello,

I hope you all are well.

I want to insert text from an excel-cell (B16) into a word document. The text should be inserted after the respective bookmark ("B1").


I have written the following code:


VBA Code:
Sub InsertAfterBookmark()


Dim objWord As Object

Dim ws As Worksheet



Set ws = ThisWorkbook.Sheets(1)

Set objWord = CreateObject("Word.Application")

objWord.Visible = True

objWord.Documents.Open ("path of word document”)

With objWord.ActiveDocument

    .Bookmarks("B1").Range.Text = ws.Range("B16").Value

End With

Set objWord = Nothing


End Sub


Sadly, the macro inserts the the at the bookmark, rather than after the bookmark B1.

Do you have an idea how I can fix my code to insert the text after the bookmark?


Best regards and many thanks in advance

Sarah
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Replace this line
.Bookmarks("B1").Range.Text = ws.Range("B16").Value
with
VBA Code:
.Bookmarks("B1").Range.InsertAfter ws.Range("B16").Value
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,973
Members
452,540
Latest member
haasro02

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