Bookmark Brainstormer!!!! 
Author Message
 Bookmark Brainstormer!!!!

I am relatively new to Word VBA and would appreciate the help of one the
Word Guru's out there.

I am opening a Word document and moving to a bookmark. From the bookmark I
would like to select the word to the right which is a date (long or short
format, though it will end in a paragraph mark). The question is how do I
return the date to the right of the bookmark to a variable (say for example
dateCarrier).

Thanks again and your help is appreciated:

Alastair MacFarlane

Sample Code:

Dim WrdApp As Word.Application
Dim SearchPath As String
Dim wordRange As Word.Range
Dim FileName as String
Dim DateCarrier as Date

Public Sub CalculateTotal()
Set WrdApp = New Word.Application
WrdApp.Visible = True
        WrdApp.Documents.Open FileName:=SearchPath & FileName
        If WrdApp.ActiveDocument.Bookmarks.Exists("DateToFind") = True Then
            Set wordRange = ActiveDocument.Goto(What:=wdGoToBookmark,
Name:="DateToFind")
        Else
        End If
End If
Wend
End Function



Tue, 20 Jan 2004 05:19:21 GMT  
 Bookmark Brainstormer!!!!
Hi Alastair,

Give this function a try.  I think this might be what you're looking for:

Function GetDate() As String
  Dim r As Range

  Set r = Application.ActiveDocument.Range.GoTo(What:=wdGoToBookmark,
Name:="MyBookmark")
  r.EndOf wdParagraph, wdExtend
  GetDate = r.Text
End Function

This will just return a string that contains the text from the bookmark to
the end of the paragraph (you mentioned you had a paragraph mark following
the date).  I hope that helps.  Have a great day!

Thanks,

Mark



Tue, 20 Jan 2004 05:47:54 GMT  
 Bookmark Brainstormer!!!!
Thanks for the help Mark. When I read your post I knew the
answer (funny that huh?).

Thanks again

Quote:
>-----Original Message-----
>Hi Alastair,

>Give this function a try.  I think this might be what
you're looking for:

>Function GetDate() As String
>  Dim r As Range

>  Set r = Application.ActiveDocument.Range.GoTo

(What:=wdGoToBookmark,
Quote:
>Name:="MyBookmark")
>  r.EndOf wdParagraph, wdExtend
>  GetDate = r.Text
>End Function

>This will just return a string that contains the text

from the bookmark to
Quote:
>the end of the paragraph (you mentioned you had a

paragraph mark following
Quote:
>the date).  I hope that helps.  Have a great day!

>Thanks,

>Mark

>.



Tue, 20 Jan 2004 15:41:52 GMT  
 Bookmark Brainstormer!!!!

Hi Alastair,

I don't want to mess directly with your posted code because it looks
like you may have pieces of it missing or surplus (see last 3 lines),
but this should do what you want

Dim DateCarrier as Date
Dim r As Range
Set r = ActiveDocument.Bookmarks("DateToFind").Range
r.MoveEndUntil Cset:=vbCr
DateCarrier = r.Text

Note that this operates without doing any selecting, which is generally
more efficient.  If you *must* have the date selected in addition to
assigning it to a variable, post back.


------ WWW: http://www.speakeasy.org/~mtangard ----------------------
------------- "Life is nothing if you're not obsessed." --John Waters
---------------------------------------------------------------------

Quote:
> I am relatively new to Word VBA and would appreciate the help of one the
> Word Guru's out there.

> I am opening a Word document and moving to a bookmark. From the bookmark I
> would like to select the word to the right which is a date (long or short
> format, though it will end in a paragraph mark). The question is how do I
> return the date to the right of the bookmark to a variable (say for example
> dateCarrier).

> Thanks again and your help is appreciated:

> Alastair MacFarlane

> Sample Code:

> Dim WrdApp As Word.Application
> Dim SearchPath As String
> Dim wordRange As Word.Range
> Dim FileName as String
> Dim DateCarrier as Date

> Public Sub CalculateTotal()
> Set WrdApp = New Word.Application
> WrdApp.Visible = True
>         WrdApp.Documents.Open FileName:=SearchPath & FileName
>         If WrdApp.ActiveDocument.Bookmarks.Exists("DateToFind") = True Then
>             Set wordRange = ActiveDocument.Goto(What:=wdGoToBookmark,
> Name:="DateToFind")
>         Else
>         End If
> End If
> Wend
> End Function



Tue, 20 Jan 2004 20:07:58 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. no valid bookmark error message, without using bookmarks at all

2. Bookmark as Calculation of other bookmarks

3. Bookmark(2).value from other bookmark

4. replacing bookmark text in vba: bookmark deleted ?

5. Changing Bookmark's text deletes bookmark from collection

6. dbGrid bookmarks v. rdoresultset bookmarks

7. RDO bookmarks vs DAO bookmarks

8. VBA help window: Multiple windows/tabs, bookmarks, bookmarks/history pane

9. Help with 'Not a valid bookmark' bookmark message

10. ACCESS7.0: 'invalid bookmark' errormessage without using bookmarks at all!

11. I can change a bookmarks text but I loose the bookmark, how can I keep it ?

12. How do I repeat bookmark in an REF Bookmark field?

 

 
Powered by phpBB® Forum Software