Delete line from a bookmark

K

Keith74

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
 
P

Pranav Vaidya

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
 
K

Keith74

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?
 
K

Keith74

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
 
P

Pranav Vaidya

try using Selection.Delete instead of objWordDoc.Selection.Delete

Regards,
Pranav Vaidya
 
K

Keith74

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top