Finding text raised by some decimal value

V

Vince

I am trying to write a macro to find raised text, specifically, I would like
to be able to find and replace the text raised by 3.5 points.

I wrote a simple macro to simply find the raised text:

' Macro to find text raised by 3 points and it works great
With ActiveDocument.Range.Find
.ClearFormatting
.Font.Position = 3 ' Finds text raised by 3 points
.Execute
End With

However, when I try to find raised text, raised by some decimal value (say)
3.5, the macro simply fails!

' Macro to find text raised by 3.5 points and it fails
With ActiveDocument.Range.Find
.ClearFormatting
.Font.Position = 3.5 ' Finds text raised by 3.5 points
' msgbox(font.position) ' This returns 4!!!! Apparently, I think that
the Font.position parameter is defined as an integer
.Execute
End With


How do I go about this? Is there someway to get it to accept and decimal
values as well? I also tried recording a macro after typing "3.5" in word's
Find and Replace box. The macro recorded doesn't work either and returns 4
as well. Is this some bug?

Thanks for any response.

Vince
 
H

Helmut Weber

Hi Vince,
Thanks for any response

if so, then
some kind of inconsistency, I'd say,
as .font.position is of type long,
according to help.

However, when searching for .Font.Position = 3.5
.Font.Position = 3.5 ' Finds text raised by 3.5 points
the search is successful.
' msgbox(font.position) ' This returns 4!!!!

That's 3.5 rounded.

But you know, it's 3.5

So what's the problem?

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
V

Vince

Hey Helmut,

Are you sure the search is successful? What am I doing wrong? I just tried
this again:

Example:
Blah blah1 blah blah

The 1 in the example is raised by 3 points.

Code:
Dim A As Range
Set A = ActiveDocument.Range

With A.Find
.ClearFormatting
.Font.Position = 3
.Execute
MsgBox .Found
End With

I get "TRUE" which is good.

Now, the same example, with 1 raised by 3.5 points, and this code:

Dim A As Range
Set A = ActiveDocument.Range

With A.Find
.ClearFormatting
.Font.Position = 3.5


.Execute
MsgBox .Found
End With


gives me a "FALSE" . Why? What I meant was when I add a message box after
the .font.position=3.5, I know it returns a rounded 4 value. I was wondering
if it was looking for a 4 value as well instead of 3.5.

What am I doing wrong and how does it work for you?

Please let me know. Is this clear? Again, I mean that font raised by decimal
points cannot be searched and replaced by code. However, rounded values are
searchable.

Thanks,
Vince
 
H

Helmut Weber

Hi Vince,

sorry, I tested it manually by typing in the reach and replace
dialog "3,5 pt" (german version), which works.
However, every trial to use 3.5 programmatically
or even feeding "3,5 pt" to the dialog using sendkeys failed.

Maybe someone else will come up with a workaraound.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
V

Vince

Hey Helmut,

Thanks for your response.

Well, I am at my wit's end. I guess the only solution (more a workaround) is
to use a range which cycles through each letter in the document and do a "if
Rangevariable.font.position>3 then blah blah".

I didn't know that Germans use a "," instead of a ".". Over here (in HK -
China), they still use a "." but, many other things are way different.

Vince
 
K

Klaus Linke

Hi Vince, Helmut,

The VBA folks defined .Position as a Long (integer), so it seems it can't handle half-integer values.

I wonder if WordBasic could come to the rescue? Or maybe the bug is already older than VBA...

Regards,
Klaus
 
K

Klaus Linke

[WordBasic to the rescue]

This seems to work:
WordBasic.EditFindFont Position:="3.5"
WordBasic.EditFind Find:="", Format:=1

(at least in the German version with "3,5" instead of "3.5")

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