-
Solved: From Excel Macro - Access a Word Document
Geeez.....seems like it should be so easy.
From an Excel macro, I'm trying to:
1) open a Word document
2) put the FormField value into an array
3) close out Word
4) ...then from another macro, use the array values to populate an Excel Spreadsheet
Currently, I'm stuck on the Documents.Open command - runtime error 424.
The Array population routine was copy/paste from a working Word macro.
[vba]
Dim MyArray(24, 2) As Integer
Sub ConvertSCQ()
Set WordApp = CreateObject("Word.Application")
fileToOpen = Application _
.GetOpenFilename("Word Files (*.doc), *doc")
WordApp.Visible = False
Documents.Open (fileToOpen)
Stop
aRay = 0
aField = 1
Do
If ActiveDocument.FormFields(aField).Name = "State" Then
aRay = aRay + 1
MyArray(aRay, 1) = ActiveDocument.FormFields(aField).Name
MyArray(aRay, 2) = ActiveDocument.FormFields(aField).Result
End If
aField = aField + 1
Loop Until aField = 25
WordApp.Quit SaveChanges:=wdDoNotSaveChanges
Set WordApp = Nothing
End Sub
[/vba]
Edited 9-May-06 by GeekGirlau. Reason: Insert vba tags.
-
WordApp is not visible by default so no need to set the Visible property to False.
Replace
[vba]Documents.Open (fileToOpen)[/vba]
With
[vba]WordApp.Documents.Open fileToOpen[/vba]
Also, don't use ActiveDocument. Set the document you open to a variable.
[vba]
Dim Doc As Object
Set Doc = WordApp.Documents.Open (fileToOpen)
[/vba]
The refer to Doc when you want to refer to the document that you opened.
-
Wagnet, one of the things that you might want to investigate is Word's ability to save the data only from a form - have a look at "Save the data from a form in Word for use in a database" in the Word Help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules