Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Superscript in Word

Status
Not open for further replies.

Gemino

Programmer
Jun 25, 2012
13
NZ
Hi,

I was wondering how do I input superscripts into word?

Essentially on my report I generate (in word) it inserts lets say "Managed60" from an array or curser. I would like to search through the document and replace any "Managed60" text with "Managed60"

I have already written the code which searches through my document, but I can't work out how to then change the 60 to be a superscript. Anyhelp would be appreciated.

Thanks,

Gemino
 
If I could somehow define the "60" as an object I could use something along the lines of lcnew.Font.superscript = .t. where lcnew = 60 but I'm not really sure how to do this?
 
If you are writing this in Word using VFP Automation of Word, then the best way to determine what your VFP Automation code should be like is to First do the work without VFP.

Without using VFP at all, go into MS Word.
Start Recording a Macro.
Do the work you want to do.
Stop Recording the Macro.
Go to Tools - Macro - Macros...
Select the Macro you just recorded
Go into Edit

Examine the VBA code to see how the work was done, and then write comparable VFP Automation code into your application.

NOTE - I just did this myself to test what the VBA code might look like. I found that there were quite a few parameters set in the VBA code that I was not interested in, so in my VFP code I most likely would not set them.

Good Luck,
JRB-Bldr

 
Right. So I have gotten this code to work
oWord.selection.Font.superscript = .t.

But now I have to get it to select the 60, my search code didn't hold onto the selection.

 
Thanks JRB-Bldr, thats what I tried to get the oWord.selection.Font.superscript = .t. working! I'll have a closer look at the selection of the 60.

Thanks

Gemino
 
After looking at the VB code, it appears as if the curser is moving through the document a set number of places. I would quite like it to find the word, rather than me specify the number of places.

I tried using my search and replace code, I thought maybe if I found the "60" and replaced it with "60" it would leave it as the selection and I could apply the subscript, but it doesn't seem to leave it selected

 
Ah, after a bit of playing around and manipulation I have it working. It does mean I need to change Managed30 in my tables to Managed#30 just so that I'm not replacing any actual values of 30 in the report.


oWord.SELECTION.FIND.Execute('#30',,,.T.,,,.T.,1)
lcFoundText=oWord.SELECTION.TEXT
DO WHILE SUBSTR(lcFoundText,1,1)='#' AND SUBSTR(lcFoundText,LEN(lcFoundText),1)='0'
oWord.SELECTION.TEXT='30'
oWord.selection.Font.superscript = .t.
oWord.SELECTION.FIND.Execute('#30',,,.T.,,,.T.,1)
lcFoundText=oWord.SELECTION.TEXT
ENDDO
 
Gemino,

Given that you've got it working, you might not want to change anything. But I think you're going about it in a long-winded way.

Part of the problem is that started by recording a macro, and then examining the code that it generates. That technique has its place, but, in many cases, it doesn't give you the best code for the job in hand. In Word, macros generally use the Selection object, whereas it's usually easier to use Range objects.

We talked in your other thread about using Range objects. These are an esssential part of Word Automation, and they really do make life easier. As I said previously, you really need to understand how they work if you are going to any serious Word automation.

In this case, all you have to do is to create a Range to cover the bit of your text that you want to superscript, and then set its Font.Superscript property to .T.

Code:
oRange.Font.Superscript = .T.

You might prefer to keep your existing code in this case. But I do recommend you get to grips with Word Automation as a whole, and Range objects in particular, if you want to do this sort of thing in the future.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top