A
Alex St-Pierre
Hi,
I execute a program from Excel that copy excel table into Word and format
the table thereafter. Sometimes (about 1 time on 3), the program stop at the
following line: .LeftIndent = CentimetersToPoints(0) (see program below)
The error message is: "Error 462": Server not available
After having an error, I can restart the macro and all works. I really don't
know what is the problem.
It seems to come with: With appWord.Selection.ParagraphFormat
The Word reference is open inside Excel (10.0) and there's no missing error.
Thanks a lot!
Alex
Dim appWord As Word.Application
Dim docWord2 As Word.Document
Dim oExcel As Object 'Excel.Application
Dim owb As Object 'Excel.Workbook
Dim oXlRng As Object 'Excel.Range
Dim tbl As Word.table
On Error Resume Next
Set appWord = GetObject(, "Word.Application")
If appWord Is Nothing Then
Set appWord = CreateObject("Word.Application")
End If
On Error GoTo 0
Set owb = oExcel.ActiveWorkBook
Set docWord2 = appWord.Documents.Add
Set oXlRng = owb.Sheets("abc").Range("TableOutput")
oXlRng.Copy
appWord.Selection.PasteExcelTable LinkedToExcel:=False,
WordFormatting:=False, RTF:=False
Set tbl = docWord2.Tables(1)
docWord2.Bookmarks(1).Delete
tbl.Select
appWord.Activate
With appWord.Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(0) 'Error here
.RightIndent = CentimetersToPoints(0)
.SpaceBefore = 2
.SpaceBeforeAuto = False
.SpaceAfter = 2
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
End With
I execute a program from Excel that copy excel table into Word and format
the table thereafter. Sometimes (about 1 time on 3), the program stop at the
following line: .LeftIndent = CentimetersToPoints(0) (see program below)
The error message is: "Error 462": Server not available
After having an error, I can restart the macro and all works. I really don't
know what is the problem.
It seems to come with: With appWord.Selection.ParagraphFormat
The Word reference is open inside Excel (10.0) and there's no missing error.
Thanks a lot!
Alex
Dim appWord As Word.Application
Dim docWord2 As Word.Document
Dim oExcel As Object 'Excel.Application
Dim owb As Object 'Excel.Workbook
Dim oXlRng As Object 'Excel.Range
Dim tbl As Word.table
On Error Resume Next
Set appWord = GetObject(, "Word.Application")
If appWord Is Nothing Then
Set appWord = CreateObject("Word.Application")
End If
On Error GoTo 0
Set owb = oExcel.ActiveWorkBook
Set docWord2 = appWord.Documents.Add
Set oXlRng = owb.Sheets("abc").Range("TableOutput")
oXlRng.Copy
appWord.Selection.PasteExcelTable LinkedToExcel:=False,
WordFormatting:=False, RTF:=False
Set tbl = docWord2.Tables(1)
docWord2.Bookmarks(1).Delete
tbl.Select
appWord.Activate
With appWord.Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(0) 'Error here
.RightIndent = CentimetersToPoints(0)
.SpaceBefore = 2
.SpaceBeforeAuto = False
.SpaceAfter = 2
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
End With