2 Things: VBA Formula to Convert 1 excel sheet to .pdf and mail from Outlook & Clear Contents from Cell

dasmith7

New Member
Joined
May 13, 2016
Messages
7
Hi,
I have scanned the forums, but nothing fits my criteria. I want to know if there is a VBA formula to convert 1 sheet in an Excel workbook to pdf and mail through Outlook. I do not want the code to attempt to SAVE the .pdf to my drive. I only want it to convert the sheet to pdf and create a new email only.

#2: Is there a formula or VBA code that will simply clear the contents of a cell. I have a workbook that employees enter their id and pull there monthly numbers. Once the id is entered, all fields automatically populate. Is there a VBA that i can use to simply clear the cell that has the ID? I want to link the CLEAR VBA to a command button. Once the employee emails their monthly numbers themselves, the employee can press CLEAR to delete their ID and data prior to someone viewing their information.
 
See if this helps:

Code:
Sub AttachActiveSheetPDF()  'original code by ZVI
Dim IsCreated As Boolean, i&, PdfFile$, OutlApp As Object
' Define PDF filename
PdfFile = ActiveWorkbook.FullName
i = InStrRev(PdfFile, ".")
If i > 1 Then PdfFile = Left(PdfFile, i - 1)
PdfFile = PdfFile & "_" & ActiveSheet.Name & ".pdf"
With ActiveSheet    ' or activeworkbook
    .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
With OutlApp.CreateItem(0)
    .Subject = "Quarterly Report"
    .To = "bugs.bunny@hotmail.com"
    '    .CC = "..." ' <-- Put email of 'copy to' recipient here
    .Body = "Hi," & vbLf & vbLf & "The report is attached in PDF format." & vbLf & vbLf & _
    "Regards," & vbLf & Application.UserName & vbLf & vbLf
    .Attachments.Add PdfFile
    On Error Resume Next    ' try to send
    .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
Kill PdfFile
' Quit Outlook if it was created by this code
If IsCreated Then OutlApp.Quit
Set OutlApp = Nothing
End Sub
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,215,133
Messages
6,123,231
Members
449,091
Latest member
jeremy_bp001

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