Hey guys,
I have a command button which has the following code:
Private Sub CommandButton1_Click()
Dim path As String
Dim filename1 As String
Dim filename2 As String
path = "G:\Invoices\"
filename1 = Range("C3").Text
filename2 = Range("Q42").Text
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=path & filename1 & "-" & filename2 & ".xlsx", FileFormat:=xlOpenXMLWorkbook, Password:="Password123"
Application.DisplayAlerts = True
End Sub
And a macro code :
Sub TST()
Dim TempFilePath As String
Dim TempFileName As String
Dim FileFullPath As String
TempFilePath = Environ$("temp") & "\"
TempFileName = ActiveSheet.Range("C3") & "_" & ActiveSheet.Range("Q42")
FileFullPath = TempFilePath & TempFileName
ActiveSheet.ExportAsFixedFormat 0, FileFullPath
On Error Resume Next
With CreateObject("Outlook.Application").createitem(0)
.To = "[email protected]"
.Subject = "Test"
.Body = "test"
.Attachments.Add FileFullPath & ".pdf" '--- full path of the pdf where it is saved
.Send 'or use .Display to show you the email before sending it.
End With
On Error GoTo 0
Kill FileFullPath & ".pdf"
End Sub
I need to combine them as one.
How can i Do it?
Bookmarks