Tony,
Here is most of the code that is "relevant". I don't ever "save" the table,
I just populate it with values from my database. The only reason that I have
Word visible is for me to see what happens during testing, I set visible to
false for the end user.
If I run this code 2 times in a row then I get the error on the 2nd run (I
have indicated which lines errors below). If I remove the line that errors
then I am able to run the code as many times as I like without any errors.
Dim wdApp As Object
Dim docFinal As Object
Dim myRange As Object
Dim myTable As Object
Set wdApp = CreateObject("Word.Application")
wdApp.Visible = True
Set docFinal = wdApp.Documents.Add
docFinal.PageSetup.LeftMargin = wdApp.InchesToPoints(0.5)
docFinal.PageSetup.RightMargin = wdApp.InchesToPoints(0.5)
docFinal.PageSetup.TopMargin = wdApp.InchesToPoints(0.5)
docFinal.PageSetup.BottomMargin = wdApp.InchesToPoints(0.5)
docFinal.PageSetup.Orientation = wdOrientPortrait
docFinal.PageSetup.DifferentFirstPageHeaderFooter = False
docFinal.SaveAs FileName:="" & wdFname & "", FileFormat:=wdWordDocument
wdApp.ActiveWindow.View.TableGridlines = False
Set myRange = wdApp.Selection.Range
Set myTable = docFinal.Tables.Add(myRange, 1, 2,
wdWord9TableBehavior, wdAutoFitContent)
THE FOLLOWING STATEMENT IS WHERE I GET THE 462 ERROR
myTable.Rows.LeftIndent = InchesToPoints(0.3)
myTable.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
myTable.Borders(wdBorderRight).LineStyle = wdLineStyleNone
myTable.Borders(wdBorderTop).LineStyle = wdLineStyleNone
myTable.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
myTable.Borders(wdBorderHorizontal).LineStyle =
wdLineStyleNone
myTable.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
myTable.Borders(wdBorderDiagonalDown).LineStyle =
wdLineStyleNone
myTable.Borders(wdBorderDiagonalUp).LineStyle =
wdLineStyleNone
myTable.Borders.Shadow = False
' Get Roadmap steps for each Assessment question
Set rst2 = dbIASSecure.OpenRecordset(strSql1, dbOpenSnapshot)
If rst2.EOF = False Then
wdApp.Selection.Font.Bold = True
wdApp.Selection.Font.Size = "10"
wdApp.Selection.TypeText Text:="Roadmap Stage"
wdApp.Selection.MoveRight unit:=wdCell, Count:=1
wdApp.Selection.Font.Size = "10"
wdApp.Selection.TypeText Text:="Roadmap Step"
wdApp.Selection.MoveRight unit:=wdCell, Count:=1
End If
Do While rst2.EOF = False
wdApp.Selection.Font.Size = "10"
wdApp.Selection.Font.Bold = False
wdApp.Selection.TypeText Text:="" & rst2!stage & "-" & rst2!stagedesc
wdApp.Selection.MoveRight unit:=wdCell, Count:=1
wdApp.Selection.Font.Size = "10"
wdApp.Selection.Font.Bold = False
wdApp.Selection.TypeText Text:="" & rst2![Title]
wdApp.Selection.MoveRight unit:=wdCell, Count:=1
rst2.MoveNext
Loop
'delete the last blank row in the table
If wdApp.Selection.Information(wdWithInTable) = True Then
wdApp.Selection.SelectRow
wdApp.Selection.Cut
End If
rst1.MoveNext
wdApp.Selection.TypeParagraph
Loop
'Save the document and close
docFinal.SaveAs FileName:="" & wdFname & "", FileFormat:=wdWordDocument
docFinal.Close
wdApp.Quit wdDoNotSaveChanges
Set docFinal = Nothing
Set wdApp = Nothing
Thanks for the help!
Jerry
Tony Jollans said:
Hi Jerry,
You must be doing more (that's relevant) than that! For example where do you
save the indented tables you make, and where do you close the document? And
which bits of code are done twice (or more), and where in relation to this
structure?
Also, perhaps importantly, you make the Word app visible so can the user do
anything while you are running?
And finally, which statement from your first post actually errors?
--
Enjoy,
Tony
Tony -- Here is some additional code from the beginning and end - Thanks
for
your help! Jerry
Dim wdApp As Object
Dim docFinal As Object
Dim myRange As Object
Dim myTable As Object
Set wdApp = CreateObject("Word.Application")
wdApp.Visible = True
Set docFinal = wdApp.Documents.Add
docFinal.PageSetup.LeftMargin = wdApp.InchesToPoints(0.5)
docFinal.PageSetup.RightMargin = wdApp.InchesToPoints(0.5)
docFinal.PageSetup.TopMargin = wdApp.InchesToPoints(0.5)
docFinal.PageSetup.BottomMargin = wdApp.InchesToPoints(0.5)
docFinal.PageSetup.Orientation = wdOrientPortrait
docFinal.PageSetup.DifferentFirstPageHeaderFooter = False
docFinal.SaveAs FileName:="" & wdFname & "",
FileFormat:=wdWordDocument
wdApp.ActiveWindow.View.TableGridlines = False
... At End of code
wdApp.Quit wdDoNotSaveChanges
Set docFinal = Nothing
Set wdApp = Nothing
:
I'd really need to see more code but my guess is that you haven't
qualified
some reference correctly and got some implicit instantiation.
--
Enjoy,
Tony
I am using automation via Access to create a Word document with
mutiple
tables and need to left indent the tables. The code below works fine
the
first time however the 2nd time I get a 462 error - remote server
error...I
am not sure what I need to change to make this work everytime the user
runs
the code?
Set myRange = wdApp.Selection.Range
Set myTable = docFinal.Tables.Add(myRange, 1, 2, wdWord9TableBehavior,
wdAutoFitContent)
myTable.Rows.LeftIndent = InchesToPoints(0.3)
Thanks in advance for help!
Jerry