excel exportasfixedformat runtime error 13

Permalänk
Medlem

excel exportasfixedformat runtime error 13

Hur får jag ut sökvägen till filen, Delvis om jag vill använda den, bifoga den i outlook osv?

Set file = .... ger runtime error 13

Sub test()
Set oApp = GetOutlookApp
If oApp Is Nothing Then
MsgBox "Could not start Outlook.", vbInformation
Exit Sub
End If

strFileName = "Timereport_" & Excel.ActiveSheet.Name & ".pdf"
Set file = Excel.ActiveSheet.ExportAsFixedFormat(xlTypePDF, strFileName, xlQualityStandard, , , , , True)
End Sub

Permalänk
Medlem

Lägger in all kod istället, jag lyckas alltså inte lägga till filen i outlook varken som file eller set file, med set file tidigare error, med file run-timer error 438

Function GetOutlookApp() As Outlook.Application
On Error Resume Next
Set GetOutlookApp = CreateObject("Outlook.Application")
End Function

Sub test()
Set oApp = GetOutlookApp
If oApp Is Nothing Then
MsgBox "Could not start Outlook.", vbInformation
Exit Sub
End If

strFileName = "Timereport_" & Excel.ActiveSheet.Name & ".pdf"
file = Excel.ActiveSheet.ExportAsFixedFormat(xlTypePDF, strFileName, xlQualityStandard, , , , , True)

Set objMail = CreateObject("Outlook.Application")
Set objClient = objMail.CreateItem(0)

With objClient
.Subject = Left(strFileName, Len(strFileName) - 4)
.Attachment = file
.Display
End With
End Sub