I am trying to create a macro in Word to call from my Delphi application. What I want to do is after each query result (which I can already get into the document) is insert a one row table.
But, I really don't know VBA, I can fumble my way through recording macros, but I'm having some issues. So, I apologize for the code upfront, but it's MS's fault!
So I want to send my data and create a table with the fixed column widths. Send another set of data and create a second table and again until I get to the end of my dataset.
I would appreciate anyone's help in fixing my code!
leslie
But, I really don't know VBA, I can fumble my way through recording macros, but I'm having some issues. So, I apologize for the code upfront, but it's MS's fault!
So I want to send my data and create a table with the fixed column widths. Send another set of data and create a second table and again until I get to the end of my dataset.
I would appreciate anyone's help in fixing my code!
leslie
Code:
Sub MakeTable()
'
' MakeTable Macro
' Macro recorded 4/1/2004 by Leslie
'
Dim tablecount As Integer
If ActiveDocument.Tables.Count <> 0 Then
tablecount = ActiveDocument.Tables.Count
Else
tablecount = 0
End If
tablecount = tablecount + 1
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
7, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
Selection.Tables(tablecount).Columns(tablecount).PreferredWidth = InchesToPoints(0.7)
Selection.Move Unit:=wdColumn, Count:=1
Selection.SelectColumn
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(1.88)
Selection.Move Unit:=wdColumn, Count:=1
Selection.SelectColumn
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(0.63)
Selection.Move Unit:=wdColumn, Count:=1
Selection.SelectColumn
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(2.13)
Selection.Move Unit:=wdColumn, Count:=1
Selection.SelectColumn
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(0.5)
Selection.Move Unit:=wdColumn, Count:=1
Selection.SelectColumn
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(1.75)
Selection.Move Unit:=wdColumn, Count:=1
Selection.SelectColumn
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(0.5)
Selection.Move Unit:=wdColumn, Count:=1
Selection.SelectColumn
End Sub