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
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.
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
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
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.