Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

Additional erroneous book mark created when adding bookmark

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David Cuthill - 24 Nov 2004 23:34 GMT
I am using the following code to locate and place a bookmark - the
problem is after the code executes I also end up with a bookmark with
a name like _1123334 that happens to be at the same range location.
Any idea why this is taking place?

  Set oWordDoc = ActiveDocument
  TabCnt = oWordDoc.Tables.Count
   
  For i = 1 To TabCnt Step 4
    z = CStr(i)
    Set Rng = ActiveDocument.Tables(i).Range
    Rng.Copy
    Rng.Collapse wdCollapseEnd
    Rng.InsertAfter "" & vbCrLf
    Rng.Collapse wdCollapseEnd
    ActiveDocument.Bookmarks.Add Name:="BarChart" & z, Range:=Rng
    ...
    ...
  Next i

Thanks for any help.
Jean-Guy Marcil - 25 Nov 2004 03:34 GMT
David Cuthill was telling us:
David Cuthill nous racontait que :

> I am using the following code to locate and place a bookmark - the
> problem is after the code executes I also end up with a bookmark with
[quoted text clipped - 15 lines]
>     ...
>   Next i

These hidden (hidden because they start with an underscore) bookmarks are
usually added when cross references, links or TOC are added to the document.
Sometimes when you copy/paste between applications, the source or the
destination is marked with a bookmark. I haven't had the inclination to
study this, so I do not know why, but it has never caused me, or anybody I
have heard of, any problems.

I used your code on my Word 2003, and I did not see those hidden bookmarks.
As a suggestion, try to use With ... End With Statements in your code. It
executes faster and makes it lighter to read. For example, your code could
be written as:

'Do not forget to Dim and type your variables...
Dim oWordDoc As Document
Dim TabCnt As Long
Dim Rng As Range

Set oWordDoc = ActiveDocument
With oWordDoc
   TabCnt = .Tables.Count

   For i = 1 To TabCnt Step 4
       z = CStr(i)
       Set Rng = .Tables(i).Range
       With Rng

'Why Copy? You are not pasting it anywhere, are you?
'Maybe the answer to your question is in the code you
'obviously snipped out... Are you pasting?
'If not, what are you doing?
'If so, see my comments above
'            .Copy
           .Collapse wdCollapseEnd
'            .InsertAfter "" & vbCrLf
'Why the "" ? It does not do anything..., I replaced this by this line:
           .InsertParagraphAfter
           .Collapse wdCollapseEnd
       End With
       .Bookmarks.Add Name:="BarChart" & z, Range:=Rng
   Next i
End With

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

dcuthill - 25 Nov 2004 16:43 GMT
After sending this post I made one change that seemed to resolve the issue I
was having.

dim BMName as string
BMName = "BarChart" & z
ActiveDocument.Bookmarks.Add Name:=BMName, Range:=Rng

Thank you for the other suggestions. I think the copy command was left over
from something else I had been working on awhile ago.

> David Cuthill was telling us:
> David Cuthill nous racontait que :
[quoted text clipped - 60 lines]
>     Next i
> End With
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.