Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

Word Macro Processor Bug?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
paleoWordFan - 31 Jul 2007 07:42 GMT
I am writing in regard to what appears to me to be a bug in the macro
processor for Word... though it may be that I am doing something wrong.

The macro I have recorded/written is as follows:

Sub changeRaisedtoSuperscript()
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "([0-9]*)"
        .Font.Position = "2.5"
        .Replacement.Text = "\1"
        .Forward = True
        .Format = True
        .MatchWildcards = True
    End With

    With Selection.Find.Replacement.Font
        .Position = 0
        .Size = 8
        .Superscript = True
        .Subscript = False
    End With

    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

As you can see, this is a very simple macro to convert numeric characters
which are raise by 2.5 points (to simulate superscript) into real Word
superscripts.

The trouble is that whenever the macro runs, the "2.5" is interpreted as
"2". I tried all means to get the ".5" into the macro without success. I
encountered this bug in Word 2003, and now in Word 2007.

I would really appreciate if someone could suggest a solution to the problem.

Thanks

/John
Shauna Kelly - 31 Jul 2007 08:14 GMT
Hi

The VBA help files show that the .Position property returns a Long integer,
not a string. When you set the .Position as "2.5", Word will perform an
implicit conversion, and convert this to a Long, which is 2.

The real problem, however, is that through the user interface you can set
the position (raised or lowered) in half points, and Word respects your
choice. But the object model exposed to VBA only allows you to set it in
whole numbers (because it's a long integer). So from what I can see, you can
do the search-and-replace using the user interface, but you can't search for
text raised 2.5pts in VBA.

By the way, if you're only searching for formatting (and not text) you can
specify that the .Text and .Replacement.Text is just "". And, you might want
to set the .Continue property. So something like:
    With Selection.Find
        .Text = ""
        .Font.Position = 2
        .Replacement.Text = ""
        .Forward = True
        .Format = True
        .MatchWildcards = False
       .Wrap = wdFindContinue
    End With

Hope this helps.

Shauna Kelly.  Microsoft MVP.
http://www.shaunakelly.com/word

>I am writing in regard to what appears to me to be a bug in the macro
> processor for Word... though it may be that I am doing something wrong.
[quoted text clipped - 37 lines]
>
> /John
paleoWordFan - 31 Jul 2007 08:36 GMT
Thanks for your answer Shauna. I figured that it may be a type mismatch
problem (which is a bug to me). But when I tried to correct the number in the
macro to numeric --

.Font.Position = 2.5

The same problem occurs. Macro runs it with 2 rather than 2.5. I know that
because when i click on the "Replace" command, the formating shown is Raised
2 points rather than Raised 2.5

How to over come this?

I am aware of the null filler option. But this is a specific conversion macro.

Thanks

/John

> Hi
>
[quoted text clipped - 68 lines]
> >
> > /John
Russ - 31 Jul 2007 08:54 GMT
After recording a macro and looking at the results, it was
Selection.Font.Position = 2.5
Without the quote marks.

> I am writing in regard to what appears to me to be a bug in the macro
> processor for Word... though it may be that I am doing something wrong.
[quoted text clipped - 36 lines]
>
> /John

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

paleoWordFan - 31 Jul 2007 09:06 GMT
Yes, I put in the quotation marks because I was trying to get the macro to
work.

Either way --

Selection.Font.Position = 2.5

or

Selection.Font.Position = "2.5"

It does not work. Try it out. I believe it is a bug.

/John

> After recording a macro and looking at the results, it was
> Selection.Font.Position = 2.5
[quoted text clipped - 40 lines]
> >
> > /John
Klaus Linke - 31 Jul 2007 12:01 GMT
Yes, it is a bug that was introduced when the macro language changed from
WordBasic to VBA.
As Shauna said, .Position was wrongly defined as Long (that is, an integer).

WordBasic should still work:

With WordBasic
 .EditFindClearFormatting
 .EditReplaceClearFormatting
 .EditFindFont Position:="2.5"
 .EditFind Find:="", Format:=1, Wrap:=1
End With

Regards,
Klaus

> Yes, I put in the quotation marks because I was trying to get the macro to
> work.
[quoted text clipped - 59 lines]
>> >
>> > /John
Klaus Linke - 31 Jul 2007 12:09 GMT
To change all text that's raised 2.5 pt to 3 pt:

With WordBasic
 .EditFindClearFormatting
 .EditReplaceClearFormatting
 .EditFindClearFormatting
 .EditFindFont Position:="2.5"
 .EditReplaceFont Position:="3"
 .EditReplace Format:=1, Wrap:=1, ReplaceAll:=True
End With

Then you can use VBA to do the rest...

Regards,
Klaus
paleoWordFan - 31 Jul 2007 13:56 GMT
Thank you very much, Klaus! I tried it and it works!

Regards

/John

> To change all text that's raised 2.5 pt to 3 pt:
>
[quoted text clipped - 11 lines]
> Regards,
> Klaus

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.