View Single Post
 
Old 01-08-2014, 02:43 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,340
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

The following macro allows you to browse to a folder containing the documents you want to process, then process them automatically.
Code:
Sub ProcessDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, wdSrcDoc As Document, wdTgtDoc As Document
strFolder = GetFolder
If strFolder = "" Then Exit Sub
Set wdTgtDoc = ActiveDocument
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
  Set wdSrcDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
  With wdSrcDoc
    'Do your processing here
    '
    .Close SaveChanges:=False
  End With
  strFile = Dir()
Wend
Set wdSrcDoc = Nothing: Set wdTgtDoc = Nothing
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
If you run the code from your target document, all you'll need to add is the code to extract the data & update the target (where indicated by the comments in the code above). For example, the processing code for a single formfield might be something like:
Code:
wdTgtDoc.Range.InsertAfter .FormFields("MyField").Result & vbCr
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote