Hey Gang,

Back again with another question that has me pulling out the remaining two
hairs.

I have a bunch of bookmarks that I am searching for in a document and
selecting all bookmarks that do not meet that criteria to make subdocuments.
All has been working fine, but now I need to do a search for either of two
bookmark names and delete the others.

I have been trying a couple of variations of OR, but to no avail. The
original code for a given bookmark is as follows:

For Each MyBook In ActiveDocument.Bookmarks
If InStr(1, MyBook.Name, "por_") = 0 Then
MyBook.Range.Delete
End If
Next

This looks for sequenced bookmarks that start with "por_" and deletes
anything but. I want it to look for both "por_" AND "poi_" and delete
anything else. I have tried the following to no avail:

1.
For Each MyBook In ActiveDocument.Bookmarks
If InStr(1, MyBook.Name, "por_""poi_") = 0 Then
MyBook.Range.Delete
End If
Next

2.
For Each MyBook In ActiveDocument.Bookmarks
If InStr(1, MyBook.Name, "por_") = 0 OR InStr(1, MyBook.Name,
"por_") = 0 Then
MyBook.Range.Delete
End If
Next

I have tried a few others that are too embarrassing to post.

Anyone know the correct syntax? TIA!
--
Bill Foley, Microsoft MVP (PowerPoint)
Microsoft Office Specialist Master Instructor - XP
www.pttinc.com
Check out PPT FAQs at: http://www.rdpslides.com/pptfaq/
Check out Word FAQs at: http://word.mvps.org/FAQs/General/index.htm

Re: Using OR Operator in VBA Code - Problem by Jay

Jay
Fri May 27 11:12:00 CDT 2005

Bill Foley wrote:
> Hey Gang,
>
> Back again with another question that has me pulling out the
> remaining two hairs.
>
> I have a bunch of bookmarks that I am searching for in a document and
> selecting all bookmarks that do not meet that criteria to make
> subdocuments. All has been working fine, but now I need to do a
> search for either of two bookmark names and delete the others.
>
> I have been trying a couple of variations of OR, but to no avail. The
> original code for a given bookmark is as follows:
>
> For Each MyBook In ActiveDocument.Bookmarks
> If InStr(1, MyBook.Name, "por_") = 0 Then
> MyBook.Range.Delete
> End If
> Next
>
> This looks for sequenced bookmarks that start with "por_" and deletes
> anything but. I want it to look for both "por_" AND "poi_" and delete
> anything else. I have tried the following to no avail:
>
> 1.
> For Each MyBook In ActiveDocument.Bookmarks
> If InStr(1, MyBook.Name, "por_""poi_") = 0 Then
> MyBook.Range.Delete
> End If
> Next
>
> 2.
> For Each MyBook In ActiveDocument.Bookmarks
> If InStr(1, MyBook.Name, "por_") = 0 OR InStr(1, MyBook.Name,
> "por_") = 0 Then
> MyBook.Range.Delete
> End If
> Next
>
> I have tried a few others that are too embarrassing to post.
>
> Anyone know the correct syntax? TIA!

Hi Bill,

Use #2, except replace OR with AND.

#1 won't work because the expression "por_""poi_" is equivalent to the
single string por_"poi_ and that doesn't appear in any bookmark name.

In the original #2, what you're saying is "if por_ doesn't occur OR if poi_
doesn't occur in the same name, then delete". But if por_ does occur in a
particular name, then poi_ is *not* present in that name, and vice versa, so
that condition is always going to be true.

What you want is "if por_ doesn't occur AND if poi_ doesn't occur in the
same name, then delete".

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org



Re: Using OR Operator in VBA Code - Problem by Andra

Andra
Fri May 27 11:22:49 CDT 2005

it seems (sorry for not using correct vba syntax)
if ...por...= 0 AND ...poi...= 0 then
equal to
if ...por...<> 0 OR ...poi...<> 0 then do nothing else delete


Bill Foley wrote
> Hey Gang,
>
> Back again with another question that has me pulling out the remaining two
> hairs.
>
> I have a bunch of bookmarks that I am searching for in a document and
> selecting all bookmarks that do not meet that criteria to make
subdocuments.
> All has been working fine, but now I need to do a search for either of two
> bookmark names and delete the others.
>
> I have been trying a couple of variations of OR, but to no avail. The
> original code for a given bookmark is as follows:
>
> For Each MyBook In ActiveDocument.Bookmarks
> If InStr(1, MyBook.Name, "por_") = 0 Then
> MyBook.Range.Delete
> End If
> Next
>
> This looks for sequenced bookmarks that start with "por_" and deletes
> anything but. I want it to look for both "por_" AND "poi_" and delete
> anything else. I have tried the following to no avail:
>
> 1.
> For Each MyBook In ActiveDocument.Bookmarks
> If InStr(1, MyBook.Name, "por_""poi_") = 0 Then
> MyBook.Range.Delete
> End If
> Next
>
> 2.
> For Each MyBook In ActiveDocument.Bookmarks
> If InStr(1, MyBook.Name, "por_") = 0 OR InStr(1, MyBook.Name,
> "por_") = 0 Then
> MyBook.Range.Delete
> End If
> Next
>
> I have tried a few others that are too embarrassing to post.
>
> Anyone know the correct syntax? TIA!
> --
> Bill Foley, Microsoft MVP (PowerPoint)
> Microsoft Office Specialist Master Instructor - XP
> www.pttinc.com
> Check out PPT FAQs at: http://www.rdpslides.com/pptfaq/
> Check out Word FAQs at: http://word.mvps.org/FAQs/General/index.htm
>
>



Re: Using OR Operator in VBA Code - Problem by Bill

Bill
Fri May 27 11:42:36 CDT 2005

Using AND was one of the options I tried. maybe I got the syntax wrong.
I'll try again. THANKS!

--
Bill Foley, Microsoft MVP (PowerPoint)
Microsoft Office Specialist Master Instructor - XP
www.pttinc.com
Check out PPT FAQs at: http://www.rdpslides.com/pptfaq/
Check out Word FAQs at: http://word.mvps.org/FAQs/General/index.htm

"Jay Freedman" <jay.freedman@verizon.net> wrote in message
news:uWbfRbtYFHA.4024@TK2MSFTNGP10.phx.gbl...
> Bill Foley wrote:
> > Hey Gang,
> >
> > Back again with another question that has me pulling out the
> > remaining two hairs.
> >
> > I have a bunch of bookmarks that I am searching for in a document and
> > selecting all bookmarks that do not meet that criteria to make
> > subdocuments. All has been working fine, but now I need to do a
> > search for either of two bookmark names and delete the others.
> >
> > I have been trying a couple of variations of OR, but to no avail. The
> > original code for a given bookmark is as follows:
> >
> > For Each MyBook In ActiveDocument.Bookmarks
> > If InStr(1, MyBook.Name, "por_") = 0 Then
> > MyBook.Range.Delete
> > End If
> > Next
> >
> > This looks for sequenced bookmarks that start with "por_" and deletes
> > anything but. I want it to look for both "por_" AND "poi_" and delete
> > anything else. I have tried the following to no avail:
> >
> > 1.
> > For Each MyBook In ActiveDocument.Bookmarks
> > If InStr(1, MyBook.Name, "por_""poi_") = 0 Then
> > MyBook.Range.Delete
> > End If
> > Next
> >
> > 2.
> > For Each MyBook In ActiveDocument.Bookmarks
> > If InStr(1, MyBook.Name, "por_") = 0 OR InStr(1, MyBook.Name,
> > "por_") = 0 Then
> > MyBook.Range.Delete
> > End If
> > Next
> >
> > I have tried a few others that are too embarrassing to post.
> >
> > Anyone know the correct syntax? TIA!
>
> Hi Bill,
>
> Use #2, except replace OR with AND.
>
> #1 won't work because the expression "por_""poi_" is equivalent to the
> single string por_"poi_ and that doesn't appear in any bookmark name.
>
> In the original #2, what you're saying is "if por_ doesn't occur OR if
poi_
> doesn't occur in the same name, then delete". But if por_ does occur in a
> particular name, then poi_ is *not* present in that name, and vice versa,
so
> that condition is always going to be true.
>
> What you want is "if por_ doesn't occur AND if poi_ doesn't occur in the
> same name, then delete".
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
>
>



Re: Using OR Operator in VBA Code - Problem by Bill

Bill
Fri May 27 11:55:44 CDT 2005

Sure enough, it worked! Guess I had something wrong (go figure)! HA! Have
a great weekend!

--
Bill Foley, Microsoft MVP (PowerPoint)
Microsoft Office Specialist Master Instructor - XP
www.pttinc.com
Check out PPT FAQs at: http://www.rdpslides.com/pptfaq/
Check out Word FAQs at: http://word.mvps.org/FAQs/General/index.htm

"Bill Foley" <wfoley1@EATSPAMANDDIEtxu.com> wrote in message
news:OnO6XstYFHA.3624@tk2msftngp13.phx.gbl...
> Using AND was one of the options I tried. maybe I got the syntax wrong.
> I'll try again. THANKS!
>
> --
> Bill Foley, Microsoft MVP (PowerPoint)
> Microsoft Office Specialist Master Instructor - XP
> www.pttinc.com
> Check out PPT FAQs at: http://www.rdpslides.com/pptfaq/
> Check out Word FAQs at: http://word.mvps.org/FAQs/General/index.htm
>
> "Jay Freedman" <jay.freedman@verizon.net> wrote in message
> news:uWbfRbtYFHA.4024@TK2MSFTNGP10.phx.gbl...
> > Bill Foley wrote:
> > > Hey Gang,
> > >
> > > Back again with another question that has me pulling out the
> > > remaining two hairs.
> > >
> > > I have a bunch of bookmarks that I am searching for in a document and
> > > selecting all bookmarks that do not meet that criteria to make
> > > subdocuments. All has been working fine, but now I need to do a
> > > search for either of two bookmark names and delete the others.
> > >
> > > I have been trying a couple of variations of OR, but to no avail. The
> > > original code for a given bookmark is as follows:
> > >
> > > For Each MyBook In ActiveDocument.Bookmarks
> > > If InStr(1, MyBook.Name, "por_") = 0 Then
> > > MyBook.Range.Delete
> > > End If
> > > Next
> > >
> > > This looks for sequenced bookmarks that start with "por_" and deletes
> > > anything but. I want it to look for both "por_" AND "poi_" and delete
> > > anything else. I have tried the following to no avail:
> > >
> > > 1.
> > > For Each MyBook In ActiveDocument.Bookmarks
> > > If InStr(1, MyBook.Name, "por_""poi_") = 0 Then
> > > MyBook.Range.Delete
> > > End If
> > > Next
> > >
> > > 2.
> > > For Each MyBook In ActiveDocument.Bookmarks
> > > If InStr(1, MyBook.Name, "por_") = 0 OR InStr(1, MyBook.Name,
> > > "por_") = 0 Then
> > > MyBook.Range.Delete
> > > End If
> > > Next
> > >
> > > I have tried a few others that are too embarrassing to post.
> > >
> > > Anyone know the correct syntax? TIA!
> >
> > Hi Bill,
> >
> > Use #2, except replace OR with AND.
> >
> > #1 won't work because the expression "por_""poi_" is equivalent to the
> > single string por_"poi_ and that doesn't appear in any bookmark name.
> >
> > In the original #2, what you're saying is "if por_ doesn't occur OR if
> poi_
> > doesn't occur in the same name, then delete". But if por_ does occur in
a
> > particular name, then poi_ is *not* present in that name, and vice
versa,
> so
> > that condition is always going to be true.
> >
> > What you want is "if por_ doesn't occur AND if poi_ doesn't occur in the
> > same name, then delete".
> >
> > --
> > Regards,
> > Jay Freedman
> > Microsoft Word MVP FAQ: http://word.mvps.org
> >
> >
>
>



Re: Using OR Operator in VBA Code - Problem by Jezebel

Jezebel
Fri May 27 17:49:55 CDT 2005

There's also the LIKE operator --

If not Left$(MyBookmark.Name,4) like "_po[ir]" then
...






"Bill Foley" <wfoley1@EATSPAMANDDIEtxu.com> wrote in message
news:%23S5JNxsYFHA.1224@TK2MSFTNGP10.phx.gbl...
> Hey Gang,
>
> Back again with another question that has me pulling out the remaining two
> hairs.
>
> I have a bunch of bookmarks that I am searching for in a document and
> selecting all bookmarks that do not meet that criteria to make
> subdocuments.
> All has been working fine, but now I need to do a search for either of two
> bookmark names and delete the others.
>
> I have been trying a couple of variations of OR, but to no avail. The
> original code for a given bookmark is as follows:
>
> For Each MyBook In ActiveDocument.Bookmarks
> If InStr(1, MyBook.Name, "por_") = 0 Then
> MyBook.Range.Delete
> End If
> Next
>
> This looks for sequenced bookmarks that start with "por_" and deletes
> anything but. I want it to look for both "por_" AND "poi_" and delete
> anything else. I have tried the following to no avail:
>
> 1.
> For Each MyBook In ActiveDocument.Bookmarks
> If InStr(1, MyBook.Name, "por_""poi_") = 0 Then
> MyBook.Range.Delete
> End If
> Next
>
> 2.
> For Each MyBook In ActiveDocument.Bookmarks
> If InStr(1, MyBook.Name, "por_") = 0 OR InStr(1, MyBook.Name,
> "por_") = 0 Then
> MyBook.Range.Delete
> End If
> Next
>
> I have tried a few others that are too embarrassing to post.
>
> Anyone know the correct syntax? TIA!
> --
> Bill Foley, Microsoft MVP (PowerPoint)
> Microsoft Office Specialist Master Instructor - XP
> www.pttinc.com
> Check out PPT FAQs at: http://www.rdpslides.com/pptfaq/
> Check out Word FAQs at: http://word.mvps.org/FAQs/General/index.htm
>
>