Attaching pdf causing crashing

tismail

New Member
Joined
Jul 23, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello

I have an issue with below code. It does work perfectly but it keep freezing and crashing every few seconds later. Any help would be appreciated..
Thank You





Sub Save_as_PDF()

Application.ScreenUpdating = False

'Hide blank rows
For Each c In Range("C2:C38")
If c.Value = "" Then
c.EntireRow.Hidden = True
Else
c.EntireRow.Hidden = False
End If
Next

'Hide Senior and Loyalty columns
Columns("G:H").Hidden = True

'Set path to Reports folder
fPath = "T:\Ollie\Sunshine Club\Sunshine Club Sales\Reports\Sunshine Club Sales "

'Build File Name from Sheet2
Sheets(2).Range("B6").NumberFormat = "dd-mm-yy"
fName = Sheets(2).Range("B6").Text

'Save as PDF in Reports folder with date
Sheets("Sheet1").Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fPath & fName, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False

Application.ScreenUpdating = True

End Sub


Sub Email_Order_Send_Emails()

Application.ScreenUpdating = False
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
Subject = Range("Sheet2!B4")
Selected = Range("Sheet2!B7")
Recipient = Range("Sheet2!B1")
CC = Range("Sheet2!B2")
BCC = Range("Sheet2!B3")
Body = Range("Sheet2!B5")


TempFilePath = "C:\"
tempfilename = TempFilePath & Subject & ".pdf"

' Export activesheet as PDF
With Sheets(Selected)
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=tempfilename, 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 = Subject
.To = Recipient ' <-- Put email of the recipient here
.CC = CC ' <-- Put email of 'copy to' recipient here
.BCC = BCC
.Body = Body
.Attachments.Add tempfilename
.Display

' Try to send
On Error Resume Next
.Display
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 tempfilename

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

' Release the memory of object variable
Set OutlApp = Nothing
Application.ScreenUpdating = True
End Sub


Sub Reset()
'Unhide Senior and Loyalty columns
Sheets("Sheet1").Columns("G:H").Hidden = False

'Unhide blank rows
Sheets("Sheet1").Rows("2:38").EntireRow.Hidden = False



End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

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