Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 06-27-2012, 04:02 AM
macropod's Avatar
macropod macropod is offline VBA code to extract specific bookmarks from multiple word files Windows 7 64bit VBA code to extract specific bookmarks from multiple word files Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,382
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could use code like:
Code:
Sub GetBookmarks()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, wdDoc As Document
Dim ArrBkMks As String, i As Long, StrBkMk As String, StrOut As String
ArrBkMks = "Bookmark1,Bookmark2,Bookmark3"
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
  Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
  With wdDoc
    StrOut = StrOut & .Name
    For i = 0 To UBound(Split(ArrBkMks, ","))
      StrBkMk = Split(ArrBkMks, ",")(i)
      StrOut = StrOut & vbTab & StrBkMk & ": "
      If .Bookmarks.Exists(StrBkMk) Then
        StrOut = StrOut & .Bookmarks(StrBkMk).Range.Text
      End If
    Next i
  End With
  StrOut = StrOut & vbCr
  wdDoc.Close SaveChanges:=False
  strFile = Dir()
Wend
Set wdDoc = Nothing
ActiveDocument.Range.InsertAfter StrOut
Application.ScreenUpdating = True
End Sub
 
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
Simply replace the bookmark names in the 'ArrBkMks' variable with your own bookmark names, then run the macro. Point its browser to the target folder and let it run.

You'll get a list of the documents, the bookmarks and their contents exported to the active document.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA code to extract specific bookmarks from multiple word files how to extract wav files from ppts t-4-2 PowerPoint 2 01-19-2012 02:24 AM
VBA code to extract specific bookmarks from multiple word files how to transfer multiple excel cells into specific place in word document by formulas anton Excel 1 12-20-2011 03:56 AM
Extract Numbers from Zip Code Karen615 Excel 3 09-21-2011 06:54 AM
VBA code to extract specific bookmarks from multiple word files convert multiple csv files to multiple excel files mit Excel 1 06-14-2011 10:15 AM
Links between files to bookmarks in PDF spud098 Word 0 07-14-2010 01:11 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:06 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft