Deleting Shapes when a condition is met

A

aehan

Hello everyone

I'm struggling and need to ask for some help. It's probably really simple,
but my brain is not coping well at all.

I have a template which deletes/retains logos according to choices made from
a user form. It's working really well, except for one scenario and that is:

I want to delete the shapes where the criteria from one list box is met, and
the criteria from the others is not. And I've reached a mental block! The
code should be something like the "opposite" of the code below, in other
words I want to delete the logos if the text in the Combo2 box is anything
other than HR, Sales & Marketing or Product Control. Can anyone point me in
the right direction please?

Thanks for your help
Aehan

With ActiveDocument.Bookmarks("Combo1").Range
If InStr(.text, "Department 1") Then
With ActiveDocument.Bookmarks("Combo2").Range
If InStr(.text, "HR") Or InStr(.text, "Sales & Marketing")
Or _
InStr(.text, "Product Control") Then
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageHeader
With Selection.HeaderFooter
.Shapes("HR Logo").Delete
.Shapes("SM Logo").Delete
.Shapes("PC Logo").Delete
End With
End If
End With
End If
End With
 
G

Greg Maxey

Sub Test()
If InStr(ActiveDocument.Bookmarks("Combo1").Range.Text, "Department 1") Then
Select Case ActiveDocument.Bookmarks("Combo2").Range.Text
Case "HR", "Sales & Marketing", "Product Control"
'Do Nothing
Case Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
With Selection.HeaderFooter
.Shapes("HR Logo").Delete
.Shapes("SM Logo").Delete
.Shapes("PC Logo").Delete
End With
End Select
End If
End Sub
 
A

aehan

Hi Greg

Thank you very much for showing me how to write the code, I really
appreciate that. I've tried the code and it's not deleting the logos.

I'm running against a problem that I've been coming across all day - where
referring to a bookmark with ActiveDocument.Bookmarks("bmname").range.text
doesn't seem to read the text.

I've tried debugging using message boxes to return the value of the
bookmark, and when I step through the code - when it uses the Instr function,
it recognises the text and returns a message, but when the bookmark is
accessed by ActiveDocument.Bookmarks("test").range.text it doesn't read it
and the message box returns nothing. I'm really stuck. Do you have any
ideas? Thanks for helping me so far.

Aehan
 
G

Greg Maxey

Sub Testing()
'Are you saying that a line like this is not working
MsgBox ActiveDocument.Bookmarks("Combo2").Range.Text
'But if the bmrange text contained "bmtext" then this condition is met?
If InStr(ActiveDocument.Bookmarks("Combo2").Range.Text, "bmtext") Then
MsgBox "Text read"
End If
End Sub

If so then I really don't know what to tell you.

What happens when you step through the code I sent to you?
 
A

aehan

Hi Greg

It's worked!!!! I don't know what I did wrong the first time I put your
code in, but now it's excellent. I just took it slowly and worked it through
without panicking this time. Thank you very much for your help, wish I could
give you a medal!

Aehan
 

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