Man_of_Sleep
New Member
- Joined
- Aug 5, 2020
- Messages
- 19
- Office Version
- 2013
- Platform
- Windows
Hi to all Excel specialists and masters,
I have a vba code to convert the excel sheet (Sheet1) into pdf, then email the pdf.
I assigned that code to a rectangular shape, so user need to click the shape to execute the code.
The rectangular shape I've positioned in front of cells with information.
I want to make the shape disappear after user clicked it, then user can print the sheet without having the rectangular shape covered up the info.
But I also want to make the shape re-appear after user switching to the other sheet and come back the Sheet1.
Can anyone please guide me how to do that?
Sorry if my request is to much.
Thank you.
Below is my code.
I have a vba code to convert the excel sheet (Sheet1) into pdf, then email the pdf.
I assigned that code to a rectangular shape, so user need to click the shape to execute the code.
The rectangular shape I've positioned in front of cells with information.
I want to make the shape disappear after user clicked it, then user can print the sheet without having the rectangular shape covered up the info.
But I also want to make the shape re-appear after user switching to the other sheet and come back the Sheet1.
Can anyone please guide me how to do that?
Sorry if my request is to much.
Thank you.
Below is my code.
VBA Code:
Sub AttachActiveSheetPDF_01()
Dim IsCreated As Boolean
Dim PdfFile As String, Title As String
Dim OutlApp As Object
' Define PDF filename
Title = " Form for " & Range("A1").Value
PdfFile = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\" & Title & ".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 = "xxxxxxxxx" ' <-- Put email of the recipient here
.CC = "lxxxxxxxxxxx" ' <-- Put email of 'copy to' recipient here
.Body = "," & vbLf & vbLf _
& "." & vbLf & vbLf _
& "Regards," & vbLf _
& Application.UserName & vbLf & vbLf
.Attachments.Add PdfFile
' Try to send
Application.Visible = True
.Send
End With
' Quit Outlook if it was not already open
If IsCreated Then OutlApp.Quit
' Release the memory of object variable
Set OutlApp = Nothing
End Sub