run-time error '462' the remote server machine does not exist or is unavailable.

amos madanes 1 Reputation point
2021-07-30T02:59:46.07+00:00

I am trying to email a screenshot of userForm with outlook. The spreadsheet is saved in our company google drive and works without a hitch in a couple of computers, but in most It stops with the above error.

The code for the email function is:

Function outlookEmail()
Dim doc As Object

Dim OutApp As Outlook.Application 'this is an outlook object
Dim oOutlookEmail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
Set oOutlookEmail = OutApp.CreateItem(0)

On Error Resume Next
Set OutApp = GetObject(, "Outlook.Application")
If Err.Number > 0 Then Set OutApp = CreateObject("Outlook.Application")
On Error GoTo 0


Application.SendKeys "(%{1068})"
DoEvents

With oOutlookEmail
    .Display
    Set doc = .GetInspector.WordEditor
    doc.Range(0, 0).Paste
    .To = sDetail.Cells(myRow, headerDict.item("email"))
    .Subject = "documents for you"
     Application.Wait (Now + TimeValue("0:00:01"))
     Application.SendKeys "%s"
    .Send
End With

End Function

the error usually occurs in the set doc line.

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
4,366 questions
Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
6,088 questions
Office Visual Basic for Applications
Office Visual Basic for Applications
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Visual Basic for Applications: An implementation of Visual Basic that is built into Microsoft products.
1,506 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.