Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word Macro to be called from VFP
Message
 
 
To
28/08/2000 19:42:10
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00409726
Message ID:
00411229
Views:
19
Hi Peter,

I think you'll find almost everything you need in the book, just not all in one place <g>. I think I've given you what you need to know, but I reference the page numbers (and topics, in the event you're looking in the .CHM version) in the event you want more detail/clarifcation.

OK, first let me tell you how about the named parameters and constant values. Named parameters allow VBA to specify only the parameters the developer wants to change, and lets the developer specify the order. The syntax is ParameterName := ParameterValue. VFP doesn't allow it. We have to figure out what the order is, leaving blank parameters if needed. So, the line:
> Selection.HomeKey Unit:=wdLine
changes to:
oWord.Selection.HomeKey(wdLine)
because the Unit parameter is the first parameter passed. There's a little more detail on named parameters on page 16 (Chapter 2).

Chapter 2, page 17 also covers how to find the VBA constants. The quick way is to go into the VB Editor (macro editor), and press F2 to bring up the object browser. Type in "wdLine" (without the quotes) and you'll see it's value at the bottom (it's 5). There are a number of ways to get the contants -- it was discussed on the UT not long ago, and it's in the book, too, so I won't take the time here.

OK, on to what you want to do:
>All I want if I find the word 'PAge:' got to beginning of line, do the equivalent of ctrl shift down,ctrl U (select current line and underline it.
>and then how to find the next occurance of 'PAGE:"

Search and replace is covered in Chapter 5, in the "Working with existing documents" section (to find it in the .CHM file), on page 106 (if you've got the book). First, set up the search options:

oRange = oWord.ActiveDocument.Range(0,0)
WITH oRange.Find
.Text = "PAGE:"
.MatchCase = .F.
.Format = .F.
ENDWITH

Now you want to execute the code:

lFound = oRange.Find.Execute()

lFound will be .T. if the string was found. Now, you don't want to change just the "PAGE:" string, but the whole line. The object oRange contains just the string that was found. So you'll need to expand the range (see Help for this, it's not in the book, although Move is, and might work, too):

#DEFINE wdLine = 5
oRange.Expand(wdLine)

The Expand method takes one parameter to represent a unit of text, which can be wdSentence (3), or wdLine (5), or a myriad of other values.

Then you can set the font on the range (more info in Chapter 4, "Formatting," on page 50):

oRange.Font.Underline = .T.

Now collapse the range to it's endpoint (more on this on page 49):

#DEFINE wdCollapseEnd 0
oRange.Collapse(wdCollapseEnd)

You're now ready issue the .Execute() method again, which finds the next occurrence. So, wrap this in a DO WHILE, and you're all set!

>great book though
Thanks! :)

Hope this helps!

- della Martin
Previous
Reply
Map
View

Click here to load this message in the networking platform