Hi there,
I need some help with a VBA code and was wondering if anyone could help.
I needed a VBA code to email a single excel sheet from a workbook and found the code below. The problem is that when the file gets emailed to the recipient, the file name says 'TestFileScottNew.xlsm.xlsm'. In other words, the 'xlsm' part gets duplicated in the attachment and I want to prevent this from happening. I was wondering if anyone could help and let me know how to remove one of the xlsm's in the file name? (if you have a better code to help me achieve my aim then feel free to suggest it!)
Here is the code:
Any help appreciated!![]()
Sub SendWorkSheet() 'Update 20131209 Dim xFile As String Dim xFormat As Long Dim Wb As Workbook Dim Wb2 As Workbook Dim FilePath As String Dim FileName As String Dim OutlookApp As Object Dim OutlookMail As Object On Error Resume Next Application.ScreenUpdating = False Set Wb = Application.ActiveWorkbook ActiveSheet.Copy Set Wb2 = Application.ActiveWorkbook Select Case Wb.FileFormat Case xlOpenXMLWorkbook: xFile = ".xlsx" xFormat = xlOpenXMLWorkbook Case xlOpenXMLWorkbookMacroEnabled: If Wb2.HasVBProject Then xFile = ".xlsm" xFormat = xlOpenXMLWorkbookMacroEnabled Else xFile = ".xlsx" xFormat = xlOpenXMLWorkbook End If Case Excel8: xFile = ".xls" xFormat = Excel8 Case xlExcel12: xFile = ".xlsb" xFormat = xlExcel12 End Select FilePath = Environ$("temp") & "" FileName = Wb.Name Set OutlookApp = CreateObject("Outlook.Application") Set OutlookMail = OutlookApp.CreateItem(0) Wb2.SaveAs FilePath & FileName & xFile, FileFormat:=xFormat With OutlookMail .To = "xxxxx" .CC = "" .BCC = "" .Subject = "Excel sheet test" .Body = "Hello, please see file attached. Regards" .Attachments.Add Wb2.FullName .Send End With Wb2.Close Kill FilePath & FileName & xFile Set OutlookMail = Nothing Set OutlookApp = Nothing Application.ScreenUpdating = True End Sub
![]()
Bookmarks