sharky12345
Well-known Member
- Joined
- Aug 5, 2010
- Messages
- 3,422
- Office Version
- 2016
- Platform
- Windows
Guys,
I'm getting 2 errors whilst trying to create a Word document from a template.
The code I'm using is this;
The first error I get is;
That error is generated on this line;
I then get the following;
and that is generated on these 2 lines;
The odd thing is that this works fine on my home PC, but when I use it at work on a network that's when the errors are generated.
I appreciate this is actually 2 problems, but I'm sure they must be connected so can anyone spot where my problem is please?
I'm getting 2 errors whilst trying to create a Word document from a template.
The code I'm using is this;
Code:
Dim WdApp As Object
Dim myDoc As Object
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Set WdApp = CreateObject("Word.Application")
With WdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set myDoc = WdApp.Documents.Add(Template:=ThisWorkbook.Path & "\Actions\Blank Action.dotx")
With myDoc.Bookmarks
.Item("Name").Range.InsertAfter "Operational " & Sheet5.Range("B1").Value
.Item("Number").Range.InsertAfter IssueActionFrm.TextNumber.Value
.Item("Data").Range.InsertAfter Sheet5.Range("B4").Value
.Item("Priority").Range.InsertAfter IssueActionFrm.ComboGrading.Value
.Item("Originator").Range.InsertAfter "SIO"
.Item("Details").Range.InsertAfter Chr(10) & IssueActionFrm.TextDetails.Value & Chr(10)
.Item("AllocatedTo").Range.InsertAfter IssueActionFrm.TextAllocation.Value
.Item("Date").Range.InsertAfter Format(Now, "dd/mm/yyyy hh:mm")
.Item("By").Range.InsertAfter Environ("username")
If IssueActionFrm.CheckTest.Value = True Then
.Item("Test").Range.InsertAfter "YES"
End If
If IssueActionFrm.CheckVideo.Value = True Then
.Item("Video").Range.InsertAfter "YES"
.Item("Reason").Range.InsertAfter IssueActionFrm.TextReason.Value
End If
If IssueActionFrm.TextGrading.Value = "" Then
Else
.Item("Grading").Range.InsertAfter Chr(10) & IssueActionFrm.Grading.Value & Chr(10)
End If
End With
myDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
myDoc.SaveAs ThisWorkbook.Path & "\Actions\" & IssueActionFrm.TextNumber.Value & ".docx"
Select Case MsgBox("Do you want to email this Action to a recipient?", vbYesNo Or vbQuestion Or vbDefaultButton1, "Email Action")
Case vbYes
With OutMail
.To = IssueActionFrm.TextAllocation.Value
.CC = ""
.BCC = ""
.Subject = Sheet1.Range("H4").Value & " - Action " & IssueActionFrm.TextNumber.Value
.body = ""
.Attachments.Add ThisWorkbook.Path & "\Actions\" & IssueActionFrm.TextNumber.Value & ".docx"
.display
End With
Set OutMail = Nothing
Set OutApp = Nothing
Case vbNo
End Select
WdApp.NormalTemplate.Saved = True
Application.DisplayAlerts = False
myDoc.Saved = True
WdApp.Quit
Set WdApp = Nothing
Set myDoc = Nothing
The first error I get is;
Error -2147023170: Automation error. The remote procedure call failed
That error is generated on this line;
Code:
WdApp.NormalTemplate.Saved = True
I then get the following;
Error 462: The remote server machine does not exist or is unavailable
and that is generated on these 2 lines;
Code:
myDoc.Saved = True
WdApp.Quit
The odd thing is that this works fine on my home PC, but when I use it at work on a network that's when the errors are generated.
I appreciate this is actually 2 problems, but I'm sure they must be connected so can anyone spot where my problem is please?