P
Pat Hartman
I am attempting to create some complex engineering
documents. Included is a sample of one small part of the
document. The code creates a table at a bookmark. I
would then like to select the first cell of the table and
set the option to repeat the heading row should the table
have a page break. The code actually succeeds in setting
the property. However, the header does not repeat on the
second page. When I set the property manually it works.
I created a macro to do the job and in the recording mode,
the property is properly set but when I reset the property
and run the macro, the property gets set but the header
does not repeat. The 2 lines of code marked with *** are
the ones in question.
'MAX NORMAL CONDITIONS
Set rs = Application.CurrentProject.Connection.Execute
("SELECT * FROM MaxNormalConditions WHERE ModelNumber = '"
& strModel & "'")
'Loop through Items & fill table with detail
With rs
strTable = "Location" & vbTab & "Max Normal
Pressure (psig)" & vbTab & "Temp (F)" & vbTab & "Altitude
(ft)"
strTable = strTable & vbTab & "CaseID" & vbTab &
vbTab & "Max Normal Temp(F)" & vbTab & "Pressure (psig)" &
vbTab & "Altitude (ft)" & vbTab & "Case ID" & vbCr
Do Until .EOF
strTable = strTable & rs!Location & vbTab
strTable = strTable & rs!MaximumPressure &
vbTab
strTable = strTable & rs!Temp & vbTab
strTable = strTable & rs!Altitude & vbTab
strTable = strTable & rs!CaseID & vbTab & vbTab
strTable = strTable & rs!MaximumTemp & vbTab
strTable = strTable & rs!Pressure & vbTab
strTable = strTable & rs!Altitude1 & vbTab
strTable = strTable & rs!CaseID1 & vbCr
.MoveNext
Loop
InsertTextAtBookMark "MaxNormalConditions",
strTable
Set objTable = WordApp.Selection.ConvertToTable
(Separator:=vbTab)
objTable.AutoFormat
Format:=wdTableFormatProfessional ', applyshading:=True,
applyHeadingrows:=True, AutoFit:=True
*** WordApp.Selection.MoveRight Unit:=wdCell
*** WordApp.Selection.Tables(1).Rows.HeadingFormat
= True
Set objTable = Nothing
End With
I have another question and that is can I reference a
table by name rather than by index number. Each table is
inserted at a bookmark.
documents. Included is a sample of one small part of the
document. The code creates a table at a bookmark. I
would then like to select the first cell of the table and
set the option to repeat the heading row should the table
have a page break. The code actually succeeds in setting
the property. However, the header does not repeat on the
second page. When I set the property manually it works.
I created a macro to do the job and in the recording mode,
the property is properly set but when I reset the property
and run the macro, the property gets set but the header
does not repeat. The 2 lines of code marked with *** are
the ones in question.
'MAX NORMAL CONDITIONS
Set rs = Application.CurrentProject.Connection.Execute
("SELECT * FROM MaxNormalConditions WHERE ModelNumber = '"
& strModel & "'")
'Loop through Items & fill table with detail
With rs
strTable = "Location" & vbTab & "Max Normal
Pressure (psig)" & vbTab & "Temp (F)" & vbTab & "Altitude
(ft)"
strTable = strTable & vbTab & "CaseID" & vbTab &
vbTab & "Max Normal Temp(F)" & vbTab & "Pressure (psig)" &
vbTab & "Altitude (ft)" & vbTab & "Case ID" & vbCr
Do Until .EOF
strTable = strTable & rs!Location & vbTab
strTable = strTable & rs!MaximumPressure &
vbTab
strTable = strTable & rs!Temp & vbTab
strTable = strTable & rs!Altitude & vbTab
strTable = strTable & rs!CaseID & vbTab & vbTab
strTable = strTable & rs!MaximumTemp & vbTab
strTable = strTable & rs!Pressure & vbTab
strTable = strTable & rs!Altitude1 & vbTab
strTable = strTable & rs!CaseID1 & vbCr
.MoveNext
Loop
InsertTextAtBookMark "MaxNormalConditions",
strTable
Set objTable = WordApp.Selection.ConvertToTable
(Separator:=vbTab)
objTable.AutoFormat
Format:=wdTableFormatProfessional ', applyshading:=True,
applyHeadingrows:=True, AutoFit:=True
*** WordApp.Selection.MoveRight Unit:=wdCell
*** WordApp.Selection.Tables(1).Rows.HeadingFormat
= True
Set objTable = Nothing
End With
I have another question and that is can I reference a
table by name rather than by index number. Each table is
inserted at a bookmark.