I have an Access database from which I create Word documents. I'm using Office 2016. When I run the code, I either get
Error 462 "Remote server machine does not exist or is unavailable"
or
Error -2147023170 "Error: Automation error, The remote procedure call failed"
and Word closes.
On Error GoTo Err_CMD_Test
'Open Word document
Set GBL_objWord = CreateObject("Word.Application")
GBL_objWord.Visible = True
GBL_objWord.Activate
Set GBL_objDoc = GBL_objWord.Documents.Add
GBL_objDoc.Activate
'Traitement
GBL_objWord.Selection.TypeText Text:="List of something :"
GBL_objWord.Selection.TypeParagraph
GBL_objWord.Selection.TypeText Text:="Number one"
GBL_objWord.Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries(2).ListTemplates(1), ContinuePreviousList:=True, ApplyTo:=0, DefaultListBehavior:=2
GBL_objWord.Selection.TypeParagraph
GBL_objWord.Selection.TypeText Text:="Number two"
GBL_objWord.Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:=ListGalleries(wdNumberGallery).ListTemplates(1), ContinuePreviousList:=False, ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:=wdWord10ListBehavior
Exit_CMD_Test:
Exit Sub
Err_CMD_Test:
Select Case Err.Number
Case Else
MsgBox "Erreur : " & Err.Description & vbCrLf & _
"Numéro : " & Err.Number & vbCrLf & _
"Procédure : CMD_Test", vbCritical, ""
Resume Next
End Select
The code breaks on
GBL_objWord.Selection.Range.ListFormat.ApplyListTemplate _
ListTemplate:=ListGalleries(2).ListTemplates(1), _
ContinuePreviousList:=True, ApplyTo:=0, DefaultListBehavior:=2
and on
GBL_objWord.Selection.Range.ListFormat.ApplyListTemplateWithLevel _
ListTemplate:=ListGalleries(wdNumberGallery).ListTemplates(1), _
ContinuePreviousList:=False, ApplyTo:=wdListApplyToWholeList, _
DefaultListBehavior:=wdWord10ListBehavior**"
I use the methods ApplyListTemplate
and ApplyListTemplateWithLevel
just to try both and the result is the same: an error. On the first one I changed he variables wdNumberGallery
, wdListApplyToWholeList
, wdWord10ListBehavior
with their enumeration values available on MSDN website in attempt to pinpoint the error.
Unfortunately I was unable to achieve this task. What I'm looking for is to have a Word document with the following text :
List of something :
Number one
Number two
...
Thank you all for your help
The problem comes from Access VBA not recognizing
ListGalleries
when late-binding is used. If that is fully qualified with the Word.Application object, the code works for me: