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>
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>