Ugghhh i'm dying over here. I have an Access db that opens up an Instance of Word and creates a policy. The first time it goes thru ok but every other time it runs I get the following error "The requested member of the collection does not exist." There is a lot of code but I've commented most of it out to narrow down where I'm getting the error. I'm getting the error at:
objWord.ActiveDocument.Tables(intTableCount).Rows( 2).SetHeight RowHeight:=objWord.InchesToPoints(1.76), _ HeightRule:=Word.wdRowHeightExactly
I've also triedobjWord.ActiveDocument.Tables(intTableCount).Rows( 2).SetHeight RowHeight:=objWord.InchesToPoints(1.76), _
HeightRule:=wdRowHeightExactly but I get the same error.
Code:
Option Compare Database
Option Explicit
Public objWord As Object
On Error GoTo notloaded1
Set objWord = GetObject(, "Word.Application")
notloaded1:
If Err.Number <> 0 Then
Set objWord = CreateObject("Word.Application")
End If
objWord.Visible = True
objWord.Documents.Add
objWord.ActiveDocument.Sections.PageSetup.LeftMargin = objWord.InchesToPoints(0.5)
objWord.ActiveDocument.Sections.PageSetup.RightMargin = objWord.InchesToPoints(0.5)
objWord.ActiveDocument.Sections.PageSetup.TopMargin = objWord.InchesToPoints(0.5)
objWord.ActiveDocument.Sections.PageSetup.BottomMargin = objWord.InchesToPoints(0.5)
objWord.Selection.Font.Name = "Arial"
objWord.Selection.Font.Size = 10
objWord.ActiveDocument.Tables.Add Range:=objWord.Selection.Range, NumRows:=5, NumColumns:=1, DefaultTableBehavior:=wdWord8TableBehavior
intTableCount = intTableCount + 1
With objWord.Selection.ParagraphFormat
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
With objWord.Selection.Tables(1)
.Columns.PreferredWidth = objWord.InchesToPoints(7.47)
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
End With
objWord.Selection.TypeText Text:="DECLARATIONS"
objWord.Selection.TypeParagraph
objWord.Selection.TypeText Text:=strPolicyType
objWord.Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
objWord.Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
objWord.Selection.SelectCell
objWord.Selection.ParagraphFormat.Alignment = Word.wdAlignParagraphCenter
objWord.Selection.Cells.VerticalAlignment = Word.wdCellAlignVerticalTop
objWord.Selection.Font.Bold = wdToggle
objWord.Selection.MoveDown Unit:=wdLine, Count:=1
objWord.Selection.Cells.Split NumRows:=1, NumColumns:=3, MergeBeforeSplit:=False
objWord.ActiveDocument.Tables(intTableCount).Rows(2).SetHeight RowHeight:=objWord.InchesToPoints(1.76), _
HeightRule:=Word.wdRowHeightExactly
objWord.ActiveDocument.SaveAs FileName:= txtPolNumber & ".doc"
objWord.Quit
Set objWord = Nothing
Any help or ideas would be greatly appreciated! Thank you all!
Ted