Excel VBA code to email a hidden worksheet

Tony_Y

New Member
Joined
May 29, 2020
Messages
35
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have the following code which works great when my worksheet called PURGE is unhidden. However I have now hidden PURGE and the code is showing Run-time error: 5 Invalid procedure call or argument (I have highlighted in red the debug).

Any help with this issue will be greatly appreciated

TIA

Tony

VBA Code

Sub Send_Email()

Dim wFile As String, dam As Object

wFile = ThisWorkbook.Path & "\Tightness - " & Worksheets("INPUT GUIDE").Range("B26").Value & ".pdf"
Worksheets("PURGE").UsedRange.ExportAsFixedFormat Type:=xlTypePDF, Filename:=wFile, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False


Set dam = CreateObject("Outlook.Application").CreateItem(0)
dam.to = Worksheets("INPUT GUIDE").Range("K56").Value
dam.Subject = "GAS PURGE CERTIFICATE - " & Worksheets("INPUT GUIDE").Range("B26").Value
dam.body = "PLEASE SEE ATTACHED"
dam.Attachments.Add wFile
dam.Send
MsgBox "Email sent"

End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try implementing Application.ScreenUpdating = False prior to making the hidden sheet visible.

Perform the email process.
Hide the sheet.

Then implement Application.ScreenUpdating = True
 
Upvote 0
Hi Logit,

That works a treat. Thank you very much for your help. Have a good evening.

Kind regards

Tony
 
Upvote 0

Forum statistics

Threads
1,215,737
Messages
6,126,566
Members
449,318
Latest member
Son Raphon

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