Exporting Word Bookmarks to Excel

MonkeyDance1

Board Regular
Joined
Aug 19, 2015
Messages
68
Our client has Word document workbooks that they complete, and the workbooks contain bookmarks behind several of the key fields and text boxes, etc. I am trying to put together in VBA, a code that exports all of the bookmarks from a given word document, and places the results in a column in Excel.

Example, user completed the name field in the workbook (bookmark: "name1").

I want to export that bookmark, and put it in column A1 in an Excel sheet, and so on.

I'm relatively newer to VBA still, just trying to be a hero lol.

This is kind of an example: VBA Exporting Microsoft Word Bookmarks and Selection Text to Excel Spreadsheet - Stack Overflow

<code>Sub WdBkMktoXL()
Dim ObjExcel As Object, ObjWorkBook As Object, ObjWorksheet As Object
Dim Bmk() As String
Dim x As Integer, J As Integer

Set ObjExcel = CreateObject("EXCEL.APPLICATION")
Set ObjWorkBook = ObjExcel.Workbooks.Open("C:\Users")
Set ObjWorksheet = ObjWorkBook.Worksheets("Sheet1")

x = ActiveDocument.Bookmarks.Count
ReDim Bmk(x)
For J = 1 To x
Bmk(J) = ActiveDocument.Bookmarks(J).Name
ObjWorksheet.Range("A" & J) = ActiveDocument.Bookmarks(J).Range.Text
ObjWorksheet.Range("B" & J) = ActiveDocument.Bookmarks(J).Name
Next J

ObjWorkBook.Save
ObjWorkBook.Close
Set ObjWorksheet = Nothing
Set ObjWorkBook = Nothing
ObjExcel.Quit
Set ObjExcel = Nothing
End Sub




</code>
<code></code><code></code><code></code><code></code>
 

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