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 / July 2007

Tip: Looking for answers? Try searching our database.

Delete line from a bookmark

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Keith74 - 05 Jul 2007 11:01 GMT
Hi All

I have a word document where i update certain bookmarks using values
taken from a database. Sometime for a particular bookmark there is no
data to enter so i want to delete that bookmark and the entire line
that bookmark is on i.e. remove gaps in a persons address. The
problem
i'm having is this is all done via other program, none of the code is
in the document so i have to refer to the document through objects
and
because the user can open other documents while this whole process is
running using activedocument.selection is out. Can anyone point me in
the right direction using vba.

cheers

keith
Pranav Vaidya - 05 Jul 2007 11:10 GMT
Hi keith74,
I am not very sure what your code is, but I think you can try this-
Create an instance of Document object. (Dim myDoc as Document)
Instantiate this with your document
Now, you don't need to use activedocument, you can refer to your document by
this object variable.

also look at the range start, end values.

Regards,
Pranav Vaidya

> Hi All
>
[quoted text clipped - 13 lines]
>
> keith
Keith74 - 05 Jul 2007 11:26 GMT
Hi there

This is an example of something that doesn't work

       If IsNull(ADORecordset!Line1) = True Or Len(Trim(ADORecordset!
Line1)) < 1 Then
           objWordDoc.Bookmarks("Line1").Select
           objWordDoc.Bookmarks("Line1").Delete
           objWordDoc.Selection.MoveDown Unit:=5, Count:=1, Extend:=1
           objWordDoc.Selection.Delete Unit:=1, Count:=1
       Else
           objWordDoc.Bookmarks!Line1.Range.Text = Trim(ADORecordset!
Line1)
       End If

Its the "objWordDoc.Selection" that fails, object does not support etc
etc.

any ideas?
Keith74 - 05 Jul 2007 11:31 GMT
Ah, got it

objWordDoc.Bookmarks("line1").Range.Paragraphs(1).Range.Delete

thanks to a much earlier post by Jay Freedman
and thanks to you Pranav for your help

Keith
Pranav Vaidya - 05 Jul 2007 11:36 GMT
try using Selection.Delete instead of objWordDoc.Selection.Delete

Regards,
Pranav Vaidya

> Hi there
>
[quoted text clipped - 15 lines]
>
> any ideas?
Keith74 - 05 Jul 2007 17:35 GMT
I think Selection.delete only works on the active document. If the
user opens up another document while the code is running (its a long
process) the new document becomes the active one and the code explodes
in nasty messy fragments as it can't find the bookmarks
 
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.