Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-08-2014, 02:43 PM
macropod's Avatar
macropod macropod is offline Extract form fields to Word Document Windows 7 32bit Extract form fields to Word Document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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
  #2  
Old 01-08-2014, 11:43 PM
RonNCmale RonNCmale is offline Extract form fields to Word Document Windows 7 64bit Extract form fields to Word Document Office 2003
Novice
Extract form fields to Word Document
 
Join Date: Sep 2012
Posts: 15
RonNCmale is on a distinguished road
Default

First of all, I thank you Macropod for all your help, But I can't for the life of me find out where to placed the following code.

Code:
wdTgtDoc.Range.InsertAfter .FormFields("MyField").Result & vbCr
I entered in where it says
With wdSrcDoc
'Do your processing here, '


but not knowing how to code, it evidently needs more. I keep getting an error code.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting spreadsheet data rows as form fields in a document b3nz Word 3 03-31-2013 07:47 PM
Form Fields in Word jwm1346 Word 1 04-17-2012 07:02 PM
Extract form fields to Word Document Issues with Microsoft Word Form Fields hbforsyth Word 9 11-14-2011 04:26 PM
Calculating Form Fields in Microsoft Word wubba80 Word 1 06-25-2010 12:42 AM
Form fields in Word messed up mba Word VBA 0 02-07-2010 09:54 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:46 PM.


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