Word Macro Processor Bug?

P

paleoWordFan

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
 
S

Shauna Kelly

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
 
P

paleoWordFan

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

Shauna Kelly said:
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


paleoWordFan said:
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
 
R

Russ

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.

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
 
P

paleoWordFan

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

Russ said:
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.

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
 
K

Klaus Linke

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


paleoWordFan said:
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

Russ said:
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.

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
 
K

Klaus Linke

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
 

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