MS Word Range.delete problem

M

Mike O

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
 
M

macropod

hi Mike,

If you delete a bookmarked range, you delete the bookmark with it. So you need to recreate the bookmark each time. An alternative is
to toggle the state of the 'company' document property and use a field coded as:
{IF{DOCPROPERTY Company}= "ComapnyA" "Image1" "Image2"}
This way, the images don't need to be 'hidden' as such as updating them becomes as simple as updating the field concerned.

Note: The field brace pairs (ie '{ }') for the above example are created via Ctrl-F9 - you can't simply type them or copy & paste
them from this message.
 
M

Mike O

thanks for your reply

I hope you understand my point that i must hide one of the 2 logos
it's not an image control

2 pictures each in one bookmark , user is able to view one of them or none,
so i must be able to hide both as well

I don't understand your solution and how is it going to hide my picture.


macropod said:
hi Mike,

If you delete a bookmarked range, you delete the bookmark with it. So you need to recreate the bookmark each time. An alternative is
to toggle the state of the 'company' document property and use a field coded as:
{IF{DOCPROPERTY Company}= "ComapnyA" "Image1" "Image2"}
This way, the images don't need to be 'hidden' as such as updating them becomes as simple as updating the field concerned.

Note: The field brace pairs (ie '{ }') for the above example are created via Ctrl-F9 - you can't simply type them or copy & paste
them from this message.

--
Cheers
macropod
[Microsoft MVP - Word]


Mike O said:
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
 
M

macropod

Hi Mike,

As presented, the field code hides one picture and displays the other. If you want to be able to hide both images until a company
name is input, use coding like:
{IF{DOCPROPERTY Company}= "ComapnyA" "Image1"}{IF{DOCPROPERTY Company}= "ComapnyB" "Image2"}

--
Cheers
macropod
[Microsoft MVP - Word]


Mike O said:
thanks for your reply

I hope you understand my point that i must hide one of the 2 logos
it's not an image control

2 pictures each in one bookmark , user is able to view one of them or none,
so i must be able to hide both as well

I don't understand your solution and how is it going to hide my picture.


macropod said:
hi Mike,

If you delete a bookmarked range, you delete the bookmark with it. So you need to recreate the bookmark each time. An alternative
is
to toggle the state of the 'company' document property and use a field coded as:
{IF{DOCPROPERTY Company}= "ComapnyA" "Image1" "Image2"}
This way, the images don't need to be 'hidden' as such as updating them becomes as simple as updating the field concerned.

Note: The field brace pairs (ie '{ }') for the above example are created via Ctrl-F9 - you can't simply type them or copy & paste
them from this message.

--
Cheers
macropod
[Microsoft MVP - Word]


Mike O said:
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
 
M

Mike O

Hi macropod,

this really doesn't help
1- if docproperty company = company
the test will be on a dropdown selection

2- image1 ? is the url? text? ...

3- the {} give errors

i'm not vba expert.

thanks

macropod said:
Hi Mike,

As presented, the field code hides one picture and displays the other. If you want to be able to hide both images until a company
name is input, use coding like:
{IF{DOCPROPERTY Company}= "ComapnyA" "Image1"}{IF{DOCPROPERTY Company}= "ComapnyB" "Image2"}

--
Cheers
macropod
[Microsoft MVP - Word]


Mike O said:
thanks for your reply

I hope you understand my point that i must hide one of the 2 logos
it's not an image control

2 pictures each in one bookmark , user is able to view one of them or none,
so i must be able to hide both as well

I don't understand your solution and how is it going to hide my picture.


macropod said:
hi Mike,

If you delete a bookmarked range, you delete the bookmark with it. So you need to recreate the bookmark each time. An alternative
is
to toggle the state of the 'company' document property and use a field coded as:
{IF{DOCPROPERTY Company}= "ComapnyA" "Image1" "Image2"}
This way, the images don't need to be 'hidden' as such as updating them becomes as simple as updating the field concerned.

Note: The field brace pairs (ie '{ }') for the above example are created via Ctrl-F9 - you can't simply type them or copy & paste
them from this message.

--
Cheers
macropod
[Microsoft MVP - Word]



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
 
M

macropod

Hi Mike,

You would use the code attached to your dropdown to update the 'Company' document property, For example:
ActiveDocument.BuiltInDocumentProperties(wdPropertyCompany) = "Company1"
and, assuming the DOCPROPERTY field in is the body of the document:
Activedocument.Fields.Update

In the field coding I posted, "Image1" and "Image2" can be an image, text, table, a whole page of text, tables & images, etc.

As for 'the {} give errors', how did you enter the field braces? Did you follow the instructions in my original post?

--
Cheers
macropod
[Microsoft MVP - Word]


Mike O said:
Hi macropod,

this really doesn't help
1- if docproperty company = company
the test will be on a dropdown selection

2- image1 ? is the url? text? ...

3- the {} give errors

i'm not vba expert.

thanks

macropod said:
Hi Mike,

As presented, the field code hides one picture and displays the other. If you want to be able to hide both images until a company
name is input, use coding like:
{IF{DOCPROPERTY Company}= "ComapnyA" "Image1"}{IF{DOCPROPERTY Company}= "ComapnyB" "Image2"}

--
Cheers
macropod
[Microsoft MVP - Word]


Mike O said:
thanks for your reply

I hope you understand my point that i must hide one of the 2 logos
it's not an image control

2 pictures each in one bookmark , user is able to view one of them or none,
so i must be able to hide both as well

I don't understand your solution and how is it going to hide my picture.


:

hi Mike,

If you delete a bookmarked range, you delete the bookmark with it. So you need to recreate the bookmark each time. An
alternative
is
to toggle the state of the 'company' document property and use a field coded as:
{IF{DOCPROPERTY Company}= "ComapnyA" "Image1" "Image2"}
This way, the images don't need to be 'hidden' as such as updating them becomes as simple as updating the field concerned.

Note: The field brace pairs (ie '{ }') for the above example are created via Ctrl-F9 - you can't simply type them or copy &
paste
them from this message.

--
Cheers
macropod
[Microsoft MVP - Word]



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
 

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