Prev: W2003, batch converter wizard: call from cmd (batch)
Next: How to update an existing Building Block in Word 2007?
From: edamron on 16 Mar 2010 14:37 Hi. I'm need to get the text that has already been placed into a document and put it into a string variable. The text starts at a known bookmark. I was thinking about using a range object but all of the examples I see assume that I want a particular paragraph etc. The thing is I can't be sure where in the document the bookmark will appear. Is there any way to go to the bookmark (ActiveDocument.Bookmarks(DOCKETBOOKMARK).Select) and then set the range starting from the bookmark and extending 10 characters? Thanks.
From: Fumei2 via OfficeKB.com on 16 Mar 2010 15:02 Is there any way to go to the bookmark (ActiveDocument.Bookmarks (DOCKETBOOKMARK).Select) and then set the range starting from the bookmark and extending 10 characters? Yes, and you do NOT need to Select the bookmark. What do you mean by "go to"? You mention set the range. The following makes a Range object as you describe, but it is NOT selected. There is no "go to". Dim r As Range Set r = ActiveDocument.Range( _ Start:= ActiveDocument.Bookmarks(DOCKETBOOKMARK).Range _ End + 1, _ End:=ActiveDocument.Bookmarks(DOCKETBOOKMARK).Range _ End + 11) Voila. A range object that starts the NEXT character after DOCKETBOOKMARK, and is 10 characters in length. edamron wrote: >Hi. I'm need to get the text that has already been placed into a >document and put it into a string variable. The text starts at a >known bookmark. > >I was thinking about using a range object but all of the examples I >see assume that I want a particular paragraph etc. The thing is I >can't be sure where in the document the bookmark will appear. > >Is there any way to go to the bookmark >(ActiveDocument.Bookmarks(DOCKETBOOKMARK).Select) and then set the >range starting from the bookmark and extending 10 characters? > >Thanks. -- Gerry Message posted via http://www.officekb.com
From: Fumei2 via OfficeKB.com on 16 Mar 2010 15:08 Or to be more specific to your stated objective: "I'm need to get the text that has already been placed into a document and put it into a string variable." Dim strMyVar As String Dim r As Range Set r = ActiveDocument.Range( _ Start:= ActiveDocument.Bookmarks(DOCKETBOOKMARK).Range _ End + 1, _ End:=ActiveDocument.Bookmarks(DOCKETBOOKMARK).Range _ End + 11) strMyVar = r.Text The variable strMyVar contains the text starting from the first character after the bookmark DOCKETBOOKMARK, for 10 characters. NOTE: there is no error trapping on this! edamron wrote: >Hi. I'm need to get the text that has already been placed into a >document and put it into a string variable. The text starts at a >known bookmark. > >I was thinking about using a range object but all of the examples I >see assume that I want a particular paragraph etc. The thing is I >can't be sure where in the document the bookmark will appear. > >Is there any way to go to the bookmark >(ActiveDocument.Bookmarks(DOCKETBOOKMARK).Select) and then set the >range starting from the bookmark and extending 10 characters? > >Thanks. -- Gerry Message posted via http://www.officekb.com
From: Fumei2 via OfficeKB.com on 16 Mar 2010 15:08 Or to be more specific to your stated objective: "I'm need to get the text that has already been placed into a document and put it into a string variable." Dim strMyVar As String Dim r As Range Set r = ActiveDocument.Range( _ Start:= ActiveDocument.Bookmarks(DOCKETBOOKMARK).Range _ End + 1, _ End:=ActiveDocument.Bookmarks(DOCKETBOOKMARK).Range _ End + 11) strMyVar = r.Text The variable strMyVar contains the text starting from the first character after the bookmark DOCKETBOOKMARK, for 10 characters. Nothing is selected. NOTE: there is no error trapping on this! edamron wrote: >Hi. I'm need to get the text that has already been placed into a >document and put it into a string variable. The text starts at a >known bookmark. > >I was thinking about using a range object but all of the examples I >see assume that I want a particular paragraph etc. The thing is I >can't be sure where in the document the bookmark will appear. > >Is there any way to go to the bookmark >(ActiveDocument.Bookmarks(DOCKETBOOKMARK).Select) and then set the >range starting from the bookmark and extending 10 characters? > >Thanks. -- Gerry Message posted via http://www.officekb.com
From: edamron on 16 Mar 2010 17:08
That's perfect! Thanks Gerry! |