font size changes in macro

P

Patricia Shannon

I am reviewing houndreds of documents. I have a macro that closes the current
document and opens the next document in the same folder. For .txt files, I
want to retain formatting once I've set it to make it easier to review the
document.
I was able to do so with page orientation, page margins, and font type.
However, when I set font size to 9, it usually stays there for a few times
thru the macro, then goes to 9999999, which sometimes then reverts to 10.
So I have hard-coded the font size.

I put a bunch of "debug.print"s in the macro, and the place where the font
size changes seems to be fairly random. In fact, sometimes I have seen the
following situation (with relevant parts of the code):

Dim HoldRange As Range
....
With ActiveDocument
Set HoldRange = Selection.Range
HoldRange.WholeStory
....
HoldRange.Font.Size = 9
Debug.Print "Final font size ="; HoldRange.Font.Size

The Debug.print shows the print size as 9999999
even though the immediately preceding statement set it to 9 !


----------------
This post is a suggestion for Microsoft, and Microsoft responds to the
suggestions with the most votes. To vote for this suggestion, click the "I
Agree" button in the message pane. If you do not see the button, follow this
link to open the suggestion in the Microsoft Web-based Newsreader and then
click "I Agree" in the message pane.

http://www.microsoft.com/communitie...34848e59&dg=microsoft.public.word.vba.general
 
J

Jezebel

9999999 is a Word value that means 'undefined'. In respect of fonts sizes,
it means that the range you're testing has more than one size. It's the VBA
equivalent of Word displaying a blank instead of a value. Which doesn't
explain the cause of the problem, however. No way to say from the snippet
you've posted, but presumably there's more going on with your HoldRange. Are
there character styles applied to any parts of your text?

These lines --
With ActiveDocument
Set HoldRange = Selection.Range
HoldRange.WholeStory

are equivalent to

Set HoldRange = ActiveDocument.Content

So to set the lot to 9pt, you could use

ActiveDocument.Content.Font.Size = 9
 
P

Patricia Shannon

Thank you. I'll try that next time I run use this macro and let you know if
it helped.
It might not be for several days, or even next week.
What's weird to me is that sometimes the same code is ok, sometimes I get
the 9999999.
Before I execute the macro for the first time, I select the document with
Ctrl+a and set the font to size 9 (or whatever). So I would think any part of
it would have the desired font size. I've noticed that the macro will run at
least a few times w/o changing to 9999999.
I wouldn't think it would have any styles, as these are just .txt files. I
I'm using Word so that I use my macro to make it easier to look at the files,
and process all the ones in a folder. I don't think I've ever set up a style.
 

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