PDA

View Full Version : Help with clear bookmark



mike009
06-18-2009, 05:23 AM
I have 3 book marks A, B and C

A = Empty
B and C = contain hidden images

when user chooses for company B, i copy B to A --> works OK
when user modify and choose for C, I DELETE useng myRang.delte, then copy C to A --> works OK

now for the third time, if user decide to modify , i got error that A has been deleted??

here is similar code

If ActiveDocument.Bookmarks.Exists("A") Then
Dim myRange As Range
Set myRange = ActiveDocument.Bookmarks("A").Range
Else
MsgBox "ERROR, bookmark has been delteed"
End If



HideLogos 'Methode to hide logos B and C
myRange.Delete
Select Case Me.cboCompany.Value

Case "B"
'ActiveDocument.CustomDocumentProperties("Company") = "B"
With ActiveDocument.Bookmarks("A").Range.InlineShapes(1)

.Width = logoFirstPageWidth
.LockAspectRatio = msoFalse
.Height = logoFirstPageHeight
.PictureFormat.Brightness = 0.5
.PictureFormat.Contrast = 0.5
.Range.Copy
End With
myRange.Paste
HideLogos

Case "C"
'ActiveDocument.CustomDocumentProperties("Company") = C"
With ActiveDocument.Bookmarks("A").Range.InlineShapes(1)
.Width = logoFirstPageWidth
.LockAspectRatio = msoFalse
.Height = logoFirstPageHeight
.PictureFormat.Brightness = 0.5
.PictureFormat.Contrast = 0.5
.Range.Copy
End With
myRange.Paste
HideLogos

End Select

fumei
06-18-2009, 12:56 PM
If you delete the range of a bookmark, then...you delete the range of the bookmark. The bookmark is gone.

macropod
06-18-2009, 04:14 PM
Hi mike009,

You have already asked this in microsoft.public.office.developer.vba, where I gave you essentially the same reply as fumei - and two possible alternative approaches. You should at least have the courtesy to acknowledge that when posting to a different forum. See: http://www.excelguru.ca/node/7

fumei
06-19-2009, 09:34 AM
Thanks macropod. I will not waste any time suggesting alternatives myself.

fumei
06-19-2009, 10:10 AM
Although......after looking at the thread itself...ummmm, while macropod is quite correct - you should tell us when you have posted elsewhere - I believe there is some legitimate confusion.

You are asking about bookmarks, and macropod's responses used DOCPROPERTY. With all due respect to macropod, perhaps an explanation of the whys and hows of switching from the OP use of bookmarks, to using DOCPROPERTY may have helped. There was, IMHO, some real confusion.

That being said...Mike, macropod is still correct. It is polite to mention that you have posted the same question elsewhere.

Further, it is NOT polite to just abandon an existing thread/conversation (and go somewhere else) because you are either: not happy with the responses; or you simply do not understand them. You could have tried to persist on that other thread and tried to get macropod to explain in more detail. He is quite capable of doing so.

I will not argue the this or that of using fields like DOCPROPERTY versus bookmarks as you used.

macropod is - quite literally - a world expert on the use of fields in Word. I will never come close to the level of knowledge there. I will not even try to comment on this.

I will however, return to your use of bookmarks.

1. Do not delete the range.

2. use code to replace the contents of the bookmark. essentially what that means is, yes, you delete the contents - and thus deleting the bookmark itself - but you immediately re-create the bookmark with the new contents.

That new content can be "nothing" - and empty string - or it can be your logo.

Code to do that has been posted - I know, as I have posted it - a number of times, in a number of places.

mike009
07-03-2009, 03:41 PM
fumei, macropod

Sorry about all this. I do agree, i should have told you, i have learned that. but what i learned more is that i have to read the rules, coz i really didn't know that it's not allowed.

I found another solution from my colleague,
the solution is:

i will put all photos inline, make the size very small and the hide them
then when user selected one, i show the need it one and disable the rest

thank you again and sorry for wasting your time

Have a good weekend :beerchug: