Macro running in one computer but not running in another computer

John1989

New Member
Joined
Aug 21, 2017
Messages
22
Hi,

I need to send a data in the excel to various persons through Outlook app in PDF format. So I am using the following VBA code. This works fine in my computer. But it is not running in another computer and showing " Run time error 5, Invalid Procedure call or argument". In both system, we are using Excel 2007 version. Please help.
VBA Code:
Sub AttachActiveSheetPDF()
Dim IsCreated As Boolean
Dim i As Long
Dim PdfFile As String, Title As String
Dim OutlApp As Object

' Not sure for what the Title is
Title = Range("A1")

' Define PDF filename
PdfFile = ActiveWorkbook.FullName
i = InStrRev(PdfFile, ".")
If i > 1 Then PdfFile = Left(PdfFile, i - 1)
PdfFile = PdfFile & "_" & ActiveWorkbook.Sheets("Email").Range("C1").Value & ".pdf"

' Export activesheet as PDF
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With

' Use already open Outlook if possible
On Error Resume Next
Set OutlApp = GetObject(, "Outlook.Application")
If Err Then
Set OutlApp = CreateObject("Outlook.Application")
IsCreated = True
End If
OutlApp.Visible = True
On Error GoTo 0

' Prepare e-mail with PDF attachment
With OutlApp.CreateItem(0)

' Prepare e-mail
.Subject = Title
.To = ActiveWorkbook.Sheets("Email").Range("B1")
.CC = ActiveWorkbook.Sheets("Email").Range("B2")
.Subject = ActiveWorkbook.Sheets("Email").Range("B4")
.Body = ActiveWorkbook.Sheets("Email").Range("B5")
.Attachments.Add PdfFile

' Try to send
On Error Resume Next
.Send
Application.Visible = True
If Err Then
MsgBox "E-mail was not sent", vbExclamation
Else
MsgBox "E-mail successfully sent", vbInformation
End If
On Error GoTo 0

End With

' Delete PDF file
Kill PdfFile

' Quit Outlook if it was created by this code
If IsCreated Then OutlApp.Quit

' Release the memory of object variable
Set OutlApp = Nothing

End Sub
 
Last edited by a moderator:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Do both systems have at least Office 2007 Service Pack 2 applied?

Which line is causing the error?
 
Upvote 0
Both system have 2007 service pack. I actually don't know where error starts.. When I click the macro button it shows the error
 
Upvote 0
Do you not get a Debug option when the error occurs?
 
Upvote 0
Now I installed the SaveAsPDF add for MS Office 2007 in that PC. Now it is working fine. Thanks all..
 
Upvote 0
Solution
Than you didn't have Service Pack 2 installed on that computer (and you really should). SP2 removed the need for a separate add-in to export to PDF.
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,614
Members
449,039
Latest member
Mbone Mathonsi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top