M
Morten Snedker
In Outlook 2002 I've created a macro, that will use Word for printing.
The first time I run the macro, it works fine.
The second time it fails with error:
"462: The remote server machine does not exist or is unavailable"
When the Word document has been opened and the data inserted, I wish
to leave it open for editing, which is why it is not closed.
I've pointed out the place in the code with some capital letters. It
appears I'm not controlling my Word application properly, but I can't
find my mistake. Any pointers?
Thx in advance! =B-)
Sub PrintAttachments()
On Error GoTo myErr
Dim ns As NameSpace
Dim ib As MAPIFolder
Dim msg As MailItem
Dim att As Attachment
Dim strAtt As String
Dim rcp As Recipient
Dim strFra As String
Dim strMig As String
Dim strModtagere As String
Dim strSendt As String
Dim strEmne As String
Dim strBody As String
Set ns = ThisOutlookSession.Session
Set ib = ns.GetDefaultFolder(olFolderInbox)
For Each msg In ib.Application.ActiveExplorer.Selection
'...some code not relevant
Next
Dim appWord As New Word.Application
Dim docWord As New Word.Document
Set docWord = appWord.Documents.Add
appWord.Visible = True
Selection.TypeText " " 'THIS IS WHERE IT FAILS
Selection.TypeParagraph
With Selection
.PageSetup.LeftMargin = CentimetersToPoints(3#)
.Font.Name = "Arial"
.Font.Size = 14
.Font.Bold = True
.TypeText Text:=strMig
'...bla bla...
.TypeText strBody
End With
myExit:
On Error Resume Next
Set appWord = Nothing
Set docWord = Nothing
Set ns = Nothing
Set ib = Nothing
Set MailItem = Nothing
Set att = Nothing
Exit Sub
myErr:
Debug.Print Err.Number & ": " & Err.Description
Resume Next
End Sub
The first time I run the macro, it works fine.
The second time it fails with error:
"462: The remote server machine does not exist or is unavailable"
When the Word document has been opened and the data inserted, I wish
to leave it open for editing, which is why it is not closed.
I've pointed out the place in the code with some capital letters. It
appears I'm not controlling my Word application properly, but I can't
find my mistake. Any pointers?
Thx in advance! =B-)
Sub PrintAttachments()
On Error GoTo myErr
Dim ns As NameSpace
Dim ib As MAPIFolder
Dim msg As MailItem
Dim att As Attachment
Dim strAtt As String
Dim rcp As Recipient
Dim strFra As String
Dim strMig As String
Dim strModtagere As String
Dim strSendt As String
Dim strEmne As String
Dim strBody As String
Set ns = ThisOutlookSession.Session
Set ib = ns.GetDefaultFolder(olFolderInbox)
For Each msg In ib.Application.ActiveExplorer.Selection
'...some code not relevant
Next
Dim appWord As New Word.Application
Dim docWord As New Word.Document
Set docWord = appWord.Documents.Add
appWord.Visible = True
Selection.TypeText " " 'THIS IS WHERE IT FAILS
Selection.TypeParagraph
With Selection
.PageSetup.LeftMargin = CentimetersToPoints(3#)
.Font.Name = "Arial"
.Font.Size = 14
.Font.Bold = True
.TypeText Text:=strMig
'...bla bla...
.TypeText strBody
End With
myExit:
On Error Resume Next
Set appWord = Nothing
Set docWord = Nothing
Set ns = Nothing
Set ib = Nothing
Set MailItem = Nothing
Set att = Nothing
Exit Sub
myErr:
Debug.Print Err.Number & ": " & Err.Description
Resume Next
End Sub