LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Cleaning up Macro to Copy Word Formfields into Excel

With help from macropod in the Word General Group and Jean-Yves in this group
I think I have a start on copying all the Formfield data from a series of
Word files into Excel. But I'm stuck on a command I do not fully understand.
The intent of the code is to:
1. Dim and initialize all the variables, etc.
2. Get the first filename in a directory that holds all the relevant files
3. Open each file in turn (THIS IS THE PROBLEM AREA SO FAR)
4. Read each FormField in the open file
5. Set a cell via offsets to each Formfield value
6. Close the document and repeat from step 3
7. Quit Word and clear the objects

Here is my code so far:
Sub WordToExcel()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim x As Integer
Dim y As Integer
Dim strFilename As String
Dim temp As String
Dim oFld As FormField

Set wdApp = New Word.Application
'initialise counter
x = 1
y = 1
'search for first file in directory
strFilename = Dir("C:/AAA-TriageHolder/*.doc")
Do While strFilename < ""
Set wdDoc = wdApp.Documents.Open(strFilename) '//Error message results
here
With wdDoc
For Each oFld In wdDoc
temp = oFld.Result
Range("A2").Offset(x, y) = temp
y = y + 1
Next oFld
End With

wdDoc.Close
x = x + 1
strFilename = Dir
Loop
wdApp.Quit
Set wdDoc = Nothing
Set wdApp = Nothing

End Sub

As noted above, I get an error when I run the macro saying:

Run-time error '5174':
This file could not be found.
Try one or more of the following:
*Check the spelling of the name of the document.
*Try a different file name.
(A12345.doc)

The A12345.doc is the first file in the directory, so it is clearly seeing
it in order to set the strFilename, so why can it not then find the file.

Any help greatly appreciated.
ed
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel (or other) macro for cleaning date data [email protected] Excel Discussion (Misc queries) 3 July 25th 07 12:02 AM
Copy from WORD to EXCEL using a macro..... Tee Excel Discussion (Misc queries) 1 March 1st 06 06:46 PM
Macro to copy a word doc into an excel doc Tee Excel Discussion (Misc queries) 0 February 22nd 06 12:01 PM
copy from Excel to Word by macro with certain for wmax77 Excel Discussion (Misc queries) 0 February 12th 06 11:33 AM


All times are GMT +1. The time now is 01:12 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"