T
Travis
I am preparing a questionnaire which I want to be able to parse
automatically with some VBA code and import data into an Excel
spreadsheet.
I'm having a few issues with the bookmarks though.
If I just add a bookmark to the document without selecting text, I get
an empty bookmark. Useful for navigating around a document, but not
useful for holding the stuff I want to grab from the word document.
If I select text and then add a bookmark around it, my macro works just
fine. The bookmark contains the text I want and this is easy to import
into my spreadsheet with the following macro run from Excel:
Private Sub ImportFromWordQuestionnaire_Click()
Dim WdApp As Word.Application
Dim Questionnaire As Document
Set WdApp = New Word.Application
Set Questionnaire = WdApp.Documents.Open("C:\questionnaire.doc")
Range("celldestination").Value =
Questionnaire.Bookmarks("nameofbookmark").Range.Text
Questionnaire.Close False
WdApp.Quit
Set Questionnaire = Nothing
Set WdApp = Nothing
End Sub
(Which works fine if the Word object library is referenced)
My problem is that this type of bookmark is deletable and overwritable
- useless for a questionnaire where people are supposed to be typing
stuff in.
So how do I get around that? Either I'll need code which can find the
text to the right of a bookmark, but not actually in it, or I'll need
to find a way to add bookmarks to a questionnaire which won't be
deleted when the questionnaire is filled in, and will actually contain
the text which the questionnaire respondent types into it.
Any suggestions?
Travis
automatically with some VBA code and import data into an Excel
spreadsheet.
I'm having a few issues with the bookmarks though.
If I just add a bookmark to the document without selecting text, I get
an empty bookmark. Useful for navigating around a document, but not
useful for holding the stuff I want to grab from the word document.
If I select text and then add a bookmark around it, my macro works just
fine. The bookmark contains the text I want and this is easy to import
into my spreadsheet with the following macro run from Excel:
Private Sub ImportFromWordQuestionnaire_Click()
Dim WdApp As Word.Application
Dim Questionnaire As Document
Set WdApp = New Word.Application
Set Questionnaire = WdApp.Documents.Open("C:\questionnaire.doc")
Range("celldestination").Value =
Questionnaire.Bookmarks("nameofbookmark").Range.Text
Questionnaire.Close False
WdApp.Quit
Set Questionnaire = Nothing
Set WdApp = Nothing
End Sub
(Which works fine if the Word object library is referenced)
My problem is that this type of bookmark is deletable and overwritable
- useless for a questionnaire where people are supposed to be typing
stuff in.
So how do I get around that? Either I'll need code which can find the
text to the right of a bookmark, but not actually in it, or I'll need
to find a way to add bookmarks to a questionnaire which won't be
deleted when the questionnaire is filled in, and will actually contain
the text which the questionnaire respondent types into it.
Any suggestions?
Travis