I have encountered a problem of trying to create a new document in
MS word and add a table on it:
_____________________________________________________
I typed the following codes in excel VBA editor:
Sub TestWord_MakeTables()
Dim wapp As New Word.Application
With wapp
.NewDocument.Add Filename:="xxx.doc"
End With
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2,
NumColumns:= _
5, DefaultTableBehavior:=wdWord9TableBehavior,
AutoFitBehavior:= _
wdAutoFitFixed
'.Selection.Text = "X"
'Tables.Add Range:=Selection.Range, numrows:=10, numcolumns _
:=5, DefaultTableBehavior:=wdWord9TableBehavior,
AutoFitBehavior:= _
wdAutoFitFixed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
End Sub
This is a preliminary program of my excel development program... the
sentence between the two '~~~~~~~~~~~~~~~~~~~ lines is copied from a
Macro I recorded in MS Word macro recorder.
But when i run the above segment in excel, it alerts me with "wrong
no. of parameters or incorrect properties" in that senetence.
I already set the excel vba reference to a MSWord11.0 object
library. Actually the excel & word are from the same MS office
programs.
I would like to ask what's the problem happening in the codes?
Any helps will be highly appreciated.