Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Trying to automate Word from Foxpro
Message
From
21/09/2002 09:24:40
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00702938
Message ID:
00703046
Views:
18
This message has been marked as a message which has helped to the initial question of the thread.
>I forgot to include my existing code that doesn't quite work:
>
>oWord = CREATEOBJECT('Word.Application')
>m_first="Mr. Smith"
>oWord.documents.open("c:\letter1.dot")
>oWord.activedocument.content.insertafter(m_first)
>oWord.visible = .t.
>
>In the Word Template, I create a field called "m_first". I think perhaps I did not create this right.
>
>Thanks,
>
>N.
>
>>From within VFP 7.0 I am able to instance of Word. However what I would like to do is open a Word template and perhaps replace three fields with three values from Foxpro. The user would then change the letter as necessary and then save or print it from Word. Is this possible?
>>
>>Thanks,
>>
>>Nancy.

Nancy,
With this syntax beware you're 'opening' the template file, not creating a new one based on template (that might be intentionally what you want though).

If instead you want to create a new document based on "c:\letter1.dot" then :
oWord = CREATEOBJECT('Word.Application')
with oWord
  .documents.ADD("c:\letter1.dot")
  with .ActiveDocument
    .Variables("m_first").value = "Mr. Smith"
  endwith
  .visible = .t.
endwith
If you have many variables to set it'd be better to use a function. Suppose you have fields named with same fieldnames from customer table :
select customer
oWord = CREATEOBJECT('Word.Application')
with oWord
  .documents.ADD("c:\letter1.dot")
  for ix = 1 to fcount()
    SetWordVar(field(ix),trans(eval(field(ix))))
  endfor
  .visible = .t.
endwith

function SetWordVar
lparameters tcVarName, tcVarValue
oWord.ActiveDocument.Variables(tcVarName).value = ;
 iif(empty(tcVarValue)," ",tcVarValue)
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
Previous
Reply
Map
View

Click here to load this message in the networking platform