Hi,

I've developed the following function to test if some style does exist in a
document:

Function xstyle(aStyle As String) As Boolean
Dim sty As style
On Error GoTo notexist
Set sty = ActiveDocument.Styles(aStyle)
Set sty = Nothing
xstyle = True
Exit Function
notexist:
xstyle = False
End Function

For some time this has worked, but now when the style does not exist the
statement "Set sty = ActiveDocument.Styles(aStyle)" generates an error "the
asked member of the collection does not exist" and stops execution in stead
of jumping to the label Notexist:.

What can be at hand? Why the error handling doesn't work?

Thanks for suggestions

Henk

Re: Error handling in VBA code by Jezebel

Jezebel
Fri Aug 04 05:18:37 CDT 2006

In VBA, go to Tools > Options. On the General tab, clear the 'Break on all
errors' checkbox.



"hstijnen" <hstijnen@discussions.microsoft.com> wrote in message
news:62968233-4913-44E7-A050-3A53ACF34695@microsoft.com...
> Hi,
>
> I've developed the following function to test if some style does exist in
> a
> document:
>
> Function xstyle(aStyle As String) As Boolean
> Dim sty As style
> On Error GoTo notexist
> Set sty = ActiveDocument.Styles(aStyle)
> Set sty = Nothing
> xstyle = True
> Exit Function
> notexist:
> xstyle = False
> End Function
>
> For some time this has worked, but now when the style does not exist the
> statement "Set sty = ActiveDocument.Styles(aStyle)" generates an error
> "the
> asked member of the collection does not exist" and stops execution in
> stead
> of jumping to the label Notexist:.
>
> What can be at hand? Why the error handling doesn't work?
>
> Thanks for suggestions
>
> Henk



Re: Error handling in VBA code by hstijnen

hstijnen
Fri Aug 04 06:02:01 CDT 2006

Thanks, Jezebel, it works.

Do you know how and where this option is stored? I mean, is it stored in the
VBA project, so that all my users have it, or is it personal for the users,
so that all users must set this option. In the last case, i s there VBA code
to do it automaticly in startup? (I've recorded my setting of the of the
option, but is didn't result in code)

Regards,
Henk

"Jezebel" wrote:

> In VBA, go to Tools > Options. On the General tab, clear the 'Break on all
> errors' checkbox.
>
>
>
> "hstijnen" <hstijnen@discussions.microsoft.com> wrote in message
> news:62968233-4913-44E7-A050-3A53ACF34695@microsoft.com...
> > Hi,
> >
> > I've developed the following function to test if some style does exist in
> > a
> > document:
> >
> > Function xstyle(aStyle As String) As Boolean
> > Dim sty As style
> > On Error GoTo notexist
> > Set sty = ActiveDocument.Styles(aStyle)
> > Set sty = Nothing
> > xstyle = True
> > Exit Function
> > notexist:
> > xstyle = False
> > End Function
> >
> > For some time this has worked, but now when the style does not exist the
> > statement "Set sty = ActiveDocument.Styles(aStyle)" generates an error
> > "the
> > asked member of the collection does not exist" and stops execution in
> > stead
> > of jumping to the label Notexist:.
> >
> > What can be at hand? Why the error handling doesn't work?
> >
> > Thanks for suggestions
> >
> > Henk
>
>
>

Re: Error handling in VBA code by Jezebel

Jezebel
Fri Aug 04 06:11:33 CDT 2006

No, I don't know where it's stored; but it's certainly local. It's switched
off by default, so you don't normally have to worry about it. If your users
don't play around in VBA, it won't be an issue; and if they do, well then
it's their problem, not yours.


"hstijnen" <hstijnen@discussions.microsoft.com> wrote in message
news:99CA8612-DB8F-4B19-BA73-CB2A3DA674A4@microsoft.com...
> Thanks, Jezebel, it works.
>
> Do you know how and where this option is stored? I mean, is it stored in
> the
> VBA project, so that all my users have it, or is it personal for the
> users,
> so that all users must set this option. In the last case, i s there VBA
> code
> to do it automaticly in startup? (I've recorded my setting of the of the
> option, but is didn't result in code)
>
> Regards,
> Henk
>
> "Jezebel" wrote:
>
>> In VBA, go to Tools > Options. On the General tab, clear the 'Break on
>> all
>> errors' checkbox.
>>
>>
>>
>> "hstijnen" <hstijnen@discussions.microsoft.com> wrote in message
>> news:62968233-4913-44E7-A050-3A53ACF34695@microsoft.com...
>> > Hi,
>> >
>> > I've developed the following function to test if some style does exist
>> > in
>> > a
>> > document:
>> >
>> > Function xstyle(aStyle As String) As Boolean
>> > Dim sty As style
>> > On Error GoTo notexist
>> > Set sty = ActiveDocument.Styles(aStyle)
>> > Set sty = Nothing
>> > xstyle = True
>> > Exit Function
>> > notexist:
>> > xstyle = False
>> > End Function
>> >
>> > For some time this has worked, but now when the style does not exist
>> > the
>> > statement "Set sty = ActiveDocument.Styles(aStyle)" generates an error
>> > "the
>> > asked member of the collection does not exist" and stops execution in
>> > stead
>> > of jumping to the label Notexist:.
>> >
>> > What can be at hand? Why the error handling doesn't work?
>> >
>> > Thanks for suggestions
>> >
>> > Henk
>>
>>
>>