Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Creating report using OLE with Word97
Message
De
22/03/1999 04:58:22
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
22/03/1999 02:54:54
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00200373
Message ID:
00200392
Vues:
10
>I am spending what seems like an inordinate amount of time trying to figure out how to create some very simple Word97 documents using OLE in VFP 5.0. I have viewed all messages in UT for the past year and a half, which have been helpful, but I still have a long way to go. I'm just about to throw in the towel.
>
>Okay, enough venting. Here are my questions:
>
>1) Is there some formula for translating VBA macro code into VFB OLE commands? For example, I want to select a column in a table i have just created. The macro code is: Selection.SelectColumn. I tried many variations of:
>
>oWord.activeDocument.tables(1).column(1).SelectColumn
>
>none of which work. Help, please!
>
>2) Likewise, once I have selected the column I want to adjust its width. Macro code is: oWord.activeDocument.tables(1).column(1).SelectColumn.
>
>How does that translate into VFP?
>
>3) Is this all really a lot more difficult than it should be, or am I dense?
>
>4) I have been spending a lot of time spinning my wheels on this. As an independent contractor, how much of this time should I charge my client?
>
>I know this is a lot for one posting, but I really need to get some results soon and this is just a small fraction of what I'd like to ask. I beg your indulgence and help. Thank you!

It's not hard and very similar to VFP object referencing. Suppose you call :
thisform.myGrid.gotfocus()
VFP returns with an error property gotfocus not found or similar for grid doesn't have a gotfocus event. If it was word message would generally be "...unknown name". So you check your "selectcolumn" in help and see that it's a method of "selection" object. But here you don't have a selection, column object, referenced as tables(1).columns(1) (tables collection first element, columns collection first element - like in VFP _screen.forms(1).myGrid.columns(1) ). So you check what methods a columns collection (or column object) has and find "select". Your VFP-word code becomes :
oWord.ActiveDocument.tables(1).columns(1).select

Now converting word macros are quite a snap :
VBA Macros use named arguments (Format := wdFormatRTF) but VFP could send positional arguments. Now for example convert save method. In help it says :
Syntax 1

expression.Save

Syntax 2

expression.Save(NoPrompt, OriginalFormat)

Syntax 3

expression.Save(Comment)

expression   Syntax 1: Required. An expression that returns a Document or Template object.

Syntax 2: Required. An expression that returns a Documents object.

Syntax 3: Required. An expression that returns a Versions object.

NoPrompt   Optional Variant. True to have Word automatically save all documents. False to have Word prompt the user to save each document that has changed since it was last saved.

OriginalFormat   Optional Variant. Specifies the way the documents are saved. Can be one of the following WdOriginalFormat constants: wdOriginalDocumentFormat, wdPromptUser, or wdWordDocument.

Comment   Optional Variant. The comment string that's saved with the version.
*And in example for Syntax 2 it has :
Documents.Save NoPrompt:=True, OriginalFormat:=wdOriginalDocumentFormat
Let's convert this to VFP :
1) We want to save activedocument (a document object) w/o prompting so we select Syntax 2.
2) We want to save as word doc, so we would use wdWordDocument
Our version would roughly be :
Documents.Save NoPrompt:=True, OriginalFormat:=wdWordDocument
Converted to VFP (replace named arguments to positional arguments - that is NoPrompt is first argument in syntax 2 and format is second) True, False is 1,0 or .t., .f.:
oWord.documents.save(.t.,wdWordDocument)
But what the hell wdWordDocument is there. It's a predefined integer value and we could either put its value there but better use it as is and define. In word97 constants list :
Global Const wdWordDocument = 0
In VFP we set it as a define :
#define wdWordDocument 0
So final in word would be :
#define wdWordDocument 0
oWord.documents.save(.t.,wdWordDocument)
A final note on this, sometimes a method, event would have the same name in VFP and you should explicitly define that you mean "object's" method,event (or a property and a method in OLE object). So you would add "object" keyword in front of method. No just one thumb of rule for that I know, just try when something should work as intended but doesn't. Also this would imply when you want to reference object's application (OLEobject.object.application.propertymethodevent).
Office constants list is in compressed form wc0993.exe. It should be on MS site, David Frankenbach's site, John Harvey's site (unfortunately don't remember URL's) and perhaps somewhere in Files section.
VBA help file is ...\Microsoft Office\Office\vbawrd8.hlp. It might not be installed and on CD.
I would charge an extra 1-2 hours for finding-testing correct syntax for an app. But sure reviewing half year messages you already past more than that amount.
You might also check "mail merge to word" class in files\classes section and add a series of :
insertmergefield(..)
tableselecttable
autoformat()
This is word.basic syntax that shouldn't be undertaken and most of the commands work in both w95 and w97.
Good luck
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform