View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default how to I import word form fields in excel

Hi yet again Richard,

After my previous effort which I now think was not what you are looking for
I felt bound to have another look at the problem and perhaps the following
might help.

It does assume that you are using FormText fields for the user to complete
with the form protected. If the form is not protected when the user fills in
the data, the field names disappear.

You then need to unprotect the document to run the code or it cannot select
the data.

If anyone has a better answer then feel free to post it because I am also
interested.

Sub Get_FormText()

Dim PathFileName
Dim objWord
Dim Variable1
Dim Variable2

PathFileName = CurDir & "\" & "DocVariable Copy Test.doc"

Set objWord = CreateObject("Word.Application")

With objWord
.Documents.Open PathFileName
.Visible = True

'Get data from a Word document DocVariable
.ActiveDocument.bookmarks("Text1").Select
Variable1 = .Selection
.ActiveDocument.bookmarks("Text2").Select
Variable2 = .Selection
End With

MsgBox "Text1 = " & Variable1 & Chr(13) & _
"Text2 = " & Variable2


End Sub


--
Regards,

OssieMac


"OssieMac" wrote:

Hi again Richard,

I think that my answer is probably misleading for what you want to achieve.
I assume that your word document has FormText fields for the user to insert
data and the example does not work on them.

--
Regards,

OssieMac


"OssieMac" wrote:

Hi Richard,

Hope this helps. It is a little sample of both writing to word document
variables and getting the values from them.

Sub Get_DocVariable()

Dim PathFileName
Dim objWord
Dim Variable1
Dim Variable2

PathFileName = CurDir & "\" & "DocVariable Copy Test.doc"

Set objWord = CreateObject("Word.Application")

With objWord
.Documents.Open PathFileName
.Visible = True

'Write data to a Word document DocVariable
.ActiveDocument.Variables("MyDocVariable1") = "Data in my first Variable"
.ActiveDocument.Variables("MyDocVariable2") = "Data in my Second Variable"

'Get data from a Word document DocVariable
Variable1 = .ActiveDocument.Variables("MyDocVariable1")
Variable2 = .ActiveDocument.Variables("MyDocVariable2")
End With

MsgBox "MyDocVariable1 = " & Variable1 & Chr(13) & _
"MyDocVariable1 = " & Variable2


End Sub


--
Regards,

OssieMac


"Richard" wrote:

I have created a word form which will be completed by several users. How do
I import specific fields from completed forms into excel.