Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
More MS Word
Message
From
03/03/2000 14:40:55
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Miscellaneous
Thread ID:
00341316
Message ID:
00341422
Views:
29
>Does anyone know how to translate the following MS Word macro to VFP code? My goal is insert "AK" if the contents of field "state" is blank.
> ActiveDocument.MailMerge.Fields.AddIf Range:=Selection.Range, MergeField:= _
> "State", Comparison:=wdMergeIfIsBlank, CompareTo:="", TrueAutoText:= _
> "MailMergeInsertIf1", TrueText:="", FalseAutoText:="MailMergeInsertIf2", _
> FalseText:=""
>Thanks in advance for your help.


Hi Mike,
That's "named argument" style and could be used in VB. Fox needs "positional arguments". That's each parameter should be in an exact position (optional ones could simply be omitted with a placeholder comma). You get the positions from command's help as :

expression.AddIf(Range, MergeField, Comparison, CompareTo, TrueAutoText, TrueText, FalseAutoText, FalseText)

So your macro translates to (assuming oWord = createobject("word.application") was used to create word object):
with oWord
  .ActiveDocument.MailMerge.Fields.AddIf( ;
     .Application.Selection.Range, ;
     "State", ;
     wdMergeIfIsBlank, ;
     , ;
     , ;
     "AK") && Last 2 are optional - no need to place further placeholders
endwith
I added "Application" to "selection" as a safe belt (with..endwith block might be in a lower level and "selection" applies to "application").
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
Next
Reply
Map
View

Click here to load this message in the networking platform