Macro to email excel worksheet

bw22277

New Member
Joined
May 22, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
In another lifetime I put together the macro below and it works as intended. (if there is an email in a specific sell, set up an email with the PDF version of the tab). Now I want to change it to email the excel version of the tab. Any ideas on the changes? I attempted to just change the ".pdf" to ".xls" but it did not work.

'If there is a mail address in AK1 create the file name and the PDF
strFName = ActiveWorkbook.Name
strFName = Left(strFName, InStrRev(strFName, ".") - 1) & "_" & sh.Name & ".pdf"

sh.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
TempFilePath & strFName, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False



'If publishing is OK create the mail
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
'Create message
On Error Resume Next
With OutMail
.to = sh.Range("AK1").Value 'Insert required address here ########
.CC = ""
.BCC = ""
.Subject = "Commission Statement for " & sh.Range("B3").Value
.Body = ""
.Attachments.Add TempFilePath & strFName
.Display 'Use only during debugging
'.Send 'Uncomment to send e-mail
End With
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
this is part of a larger macro that roles through all the tabs. It does this loop depending on if other parameters are met. the file has one tab for every salesman we have. Each salesman can only see their own information.
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,727
Members
449,049
Latest member
MiguekHeka

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