Question from VBA novice re True and False values in VBA code for Word97 
Author Message
 Question from VBA novice re True and False values in VBA code for Word97

I have a large number of templates which were converted from Word 6.0
(Word Basic). I have decided that it's time to bite the bullet and
start rewriting these templates in VBA. Most of these templates
contain code like:

With ActiveWindow.View
    .TableGridlines = False
    .ShowFieldCodes = False
    .FieldShading = True
    .WrapToWindow = True
    .Type = wdPageView
End With

However, I discovered that when a macro runs which passes True as a
parameter to the NewTemplate method of the Dialogs property, you
receive a Run-time error '9118'. (Sounds like I know what I'm talking
about here, but I'm using the terminology from an article I found on
Microsoft's Internet site
support.microsoft.com/support/kb/articles/Q160/7/57.asp)

What I was proposing to do was to change such code to, for example:

With ActiveWindow.View
    .TableGridlines = 0
    .ShowFieldCodes = 0
    .FieldShading = 1
    .WrapToWindow = 1
    .Type = wdPageView
End With

Am I being too naive in thinking that I can do this? In other words,
can I always substitute 0 for False and 1 for True?



Sat, 06 Mar 2004 08:55:10 GMT  
 Question from VBA novice re True and False values in VBA code for Word97
Hi, Barbara,

That isn't what the Microsoft KnowledgeBase article is meant to tell you.

In VBA, the numeric value of True is  -1. Always, no exceptions. (That was
also the case in WordBasic.) However, you should never need to know that --
when you mean True, just use True.

All of the values in your ActiveWindow.View example are genuine Boolean
variables, and they will accept values of True or False. Although you can
put in -1 or 0, respectively, and the code will work, that wouldn't be good
programming practice  -- you would be discarding the "self-documenting"
aspect of using True or False.

What the KnowledgeBase article says is that one specific property,
.NewTemplate in the FileNew dialog, looks like it should be a Boolean value
but -- because of a bug -- it doesn't accept a value of True. For that
property only, if you want a new template instead of a new document, you
have to use the value 1. This has no implications at all for any other
property.

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


Quote:
> I have a large number of templates which were converted from Word 6.0
> (Word Basic). I have decided that it's time to bite the bullet and
> start rewriting these templates in VBA. Most of these templates
> contain code like:

> With ActiveWindow.View
>     .TableGridlines = False
>     .ShowFieldCodes = False
>     .FieldShading = True
>     .WrapToWindow = True
>     .Type = wdPageView
> End With

> However, I discovered that when a macro runs which passes True as a
> parameter to the NewTemplate method of the Dialogs property, you
> receive a Run-time error '9118'. (Sounds like I know what I'm talking
> about here, but I'm using the terminology from an article I found on
> Microsoft's Internet site
> support.microsoft.com/support/kb/articles/Q160/7/57.asp)

> What I was proposing to do was to change such code to, for example:

> With ActiveWindow.View
>     .TableGridlines = 0
>     .ShowFieldCodes = 0
>     .FieldShading = 1
>     .WrapToWindow = 1
>     .Type = wdPageView
> End With

> Am I being too naive in thinking that I can do this? In other words,
> can I always substitute 0 for False and 1 for True?



Sat, 06 Mar 2004 12:22:22 GMT  
 Question from VBA novice re True and False values in VBA code for Word97
Jay

Thank you for your detailed reply. Well, certainly I agree with you
about not wanting to "discard the self-documenting aspect of True and
False". I had no desire to go away from this. However I recently
developed a new template in which I was using True and False, and this
caused the Run-Time Error 9118. I wasn't selecting File/New/Template -
I was actually selecting File/New/Document. Strangely too, the error
only seemed to occur intermittently.

In conclusion, I guess I'll just stick with using True and False, and
deal with any errors, if any, when they occur. Thanks again!

Barbara

Quote:

> Hi, Barbara,

> That isn't what the Microsoft KnowledgeBase article is meant to tell you.

> In VBA, the numeric value of True is  -1. Always, no exceptions. (That was
> also the case in WordBasic.) However, you should never need to know that --
> when you mean True, just use True.

> All of the values in your ActiveWindow.View example are genuine Boolean
> variables, and they will accept values of True or False. Although you can
> put in -1 or 0, respectively, and the code will work, that wouldn't be good
> programming practice  -- you would be discarding the "self-documenting"
> aspect of using True or False.

> What the KnowledgeBase article says is that one specific property,
> .NewTemplate in the FileNew dialog, looks like it should be a Boolean value
> but -- because of a bug -- it doesn't accept a value of True. For that
> property only, if you want a new template instead of a new document, you
> have to use the value 1. This has no implications at all for any other
> property.



Mon, 08 Mar 2004 14:54:25 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Word2000 VBA vs. Word97 VBA

2. Value of True and False

3. Theory Question: True & False

4. VBA coding to call an Excel VBA macro from Outlook

5. Manipulating VBA Code from VBA

6. Setting Default Value with VBA code

7. VBA Code for value from calendar

8. HowDoI set the DecimalPlaces value from VBA code?

9. How to change Required to False using VBA

10. Novice at VBA

11. VBA for Word - Please help Im a novice

12. Novice VB User Needs Help With VBA in Excel

 

 
Powered by phpBB® Forum Software