Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 To: Alexander de Rooij
  Where is Alexander de Rooij?
 Tilburg
 Netherlands
 Alexander de Rooij
 Tags
Subject: RE: Syntax error with Word 2007 automation
Thread ID: 143298 Message ID: 143317 # Views: 5 # Ratings: 0
Version: Visual FoxPro 9 Category: Microsoft Office Automation
Date: Monday, August 27, 2007 7:50:34 PM         
   


> Hi all,
>
> When I use the line below I get a syntax error form vfp 9 and thats it.
> Does anyone have a clue on this one??
>
> ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:=5, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
>
> I have used the macro recording in Word and it gives me te same code in the macro.
>
> Please help ....
>
> Greetings Alexander


That's VBA code. In VBA code parameters are named ( ie: NumColumns:=5 means NumColumns parameter value is 5 ). However in VFP you need to use positional parameters. Also you need to either have the header file for constants or write their numeric values (ie: wdWord9TableBehavior is 1, wdAutoFitFixed value is 0 )

From word VBA help file full syntax is:

expression.Add(Range, NumRows, NumColumns, DefaultTableBehavior, AutoFitBehavior)

So you need to write:

#DEFINE wdWord9TableBehavior 1
#DEFINE wdAutoFitFixed 0

oWord.ActiveDocument.Tables.Add(oWord.Selection.Range, 2,5,wdWord9TableBehavior, wdAutoFitFixed)

Here is 2 sample codes:

oword = CreateObject('Word.Application')
With oWord
 .Documents.Add
 .visible = .t.
 .activedocument.tables.add(oWord.Selection.range,2,5)
endwith	




#Define wdWithInTable  12
#Define wdStory  6
#Define wdTable  15
#Define wdCollapseEnd  0
#Define wdSeparateByCommas  2
#Define wdSeparateByParagraphs  0
#Define wdSeparateByTabs  1
#Define wdTableFormatColorful1  8
#Define wdTableFormatColorful2  9
#Define wdTableFormatColorful3  10

#Define CHR_TAB	chr(9)
#Define CHR_CR	chr(13)+chr(10)
Local loWord, lcMyTable

lcMyTable1 = "Parameters" + CHR_TAB + "Limit" + CHR_TAB + "Average" + CHR_CR ;
  + "Chlorine"   + CHR_TAB + "13.5"  + CHR_TAB + "10"      + CHR_CR ;
  + "Boron"      + CHR_TAB + "55.8"  + CHR_TAB + "45"      + CHR_CR

lcTempFile = sys(2015)+'.tmp'
Use employee
Copy fields First_name, last_name, Title ;
  to (lcTempFile) type delimited with TAB
lcMyHeader = chrtran('First Name,Last Name,Job Title',',',CHR_TAB)+CHR_CR
lcMyTable2=lcMyHeader+ChrTran(FileToStr(lcTempFile),'"','')
Erase (lcTempFile)

loWord   = newobject('word.application')
With loWord
  .Documents.Add()
  With .Selection
    .EndKey(wdStory)
    .InsertParagraphAfter()
  Endwith
  .ActiveDocument.Bookmarks.Add('StringTable') && Bookmark table positions
  With .Selection
    .EndKey(wdStory)
    .InsertParagraphAfter()
  Endwith
  .ActiveDocument.Bookmarks.Add('EmployeeTable')

  PutWordTable(loWord,lcMyTable2, 'EmployeeTable') && Add in reverse order - using bookmarks
  PutWordTable(loWord,lcMyTable1, 'StringTable')
  Clear
  .Visible = .t.
Endwith

Function PutWordTable
  Lparameters toWord, tcTable, tcBookmarkName
  With toWord.ActiveDocument
    .Bookmarks(tcBookmarkName).Select
    With .Application.Selection
      .Collapse(wdCollapseEnd)	&& Go to end of bookmark
      If .Information(wdWithInTable) && If we're in a table
        .MoveEnd(wdTable)
        .Collapse(wdCollapseEnd)	&& Get out of table
        .InsertParagraph()			&& Split table
        .Collapse(wdCollapseEnd)	&& Clear selection
      Endif
      .Text = tcTable
      loTable = .ConvertToTable(wdSeparateByTabs,,,,wdTableFormatColorful2,.f.,,,,,,.f.,,.f.)
      .Collapse(wdCollapseEnd)
    Endwith
  Endwith


Cetin Basoz

ENTIRE THREAD

Syntax error with Word 2007 automation Posted by Alexander de Rooij @ 8/27/2007 3:30:31 PM
RE: Syntax error with Word 2007 automation Posted by Mike Gagnon @ 8/27/2007 4:16:42 PM
RE: Syntax error with Word 2007 automation Posted by Alexander de Rooij @ 8/27/2007 7:30:48 PM
RE: Syntax error with Word 2007 automation Posted by Cetin Basoz @ 8/27/2007 7:50:34 PM
RE: Syntax error with Word 2007 automation Posted by Alexander de Rooij @ 8/27/2007 9:14:26 PM
RE: Syntax error with Word 2007 automation Posted by Ken Murphy @ 8/27/2007 9:17:08 PM