Hello All,
Thanks to Mania112 I have a great code that sends a PDF via email of my worksheet. And thanks to Leith it is working wonderfully with the few tweaks he provided. Now I need to take it to the next level and could use some more help. Im not sure if this is possible but here goes:
I have my code creating a file name made up of text and cell references
TempFileName = TempFilePath & sh.Name & "%" & Range("C7") & "%" & Range("L9") & ".pdf"
On a shared drive I have folders for our different pieces of equipment. These folder names are the same as cell "C7" inputs in my worksheet. Cell "C7" is changed by the user when working on a specific piece of equipment, and is that equipments ID#. What I need to have happen is save the created PDF to the specific equipment ID# folder on my shared drive (H:/). This macro is fired by button click. The path to the proper folder would need to change every time cell "C7" changed in order to go into the proper folder. I assume this save would need to happen prior to the killing of the temp file. But where exactly, and what would I need to have as the code to do this dynamic save?
Thank you all in advance for your help. Here is the full code I have.
Private Sub Save_SendToPlanner_Click()
ActiveSheet.Unprotect Password:="rental"
'Working only in 2007
Dim sh As Worksheet
Dim wb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object
TempFilePath = Environ$("temp") & "\"
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set sh = ThisWorkbook.ActiveSheet
If sh.Range("c7").Value > "0" Then
TempFileName = TempFilePath & sh.Name & "%" & Range("C7") & "%" & Range("L9") & ".pdf"
'We Publish to PDF
On Error Resume Next
sh.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=TempFileName, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
On Error GoTo 0
AdditionalText = AdditionalText & Range("C7") & Chr(13) & Range("H7") & Chr(13) & Range("H5") & Chr(13) & Range("L5") & Chr(13)
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "QC Report"
.Body = AdditionalText & Chr(13) & "Planner, Please save this QC Report to the proper file." & Chr(13) & Chr(13) & "Regards," & Chr(13) & "QC Generator"
.Attachments.Add TempFileName
.Display 'or use .Send
On Error GoTo 0
End With
Set OutMail = Nothing
If Dir(TempFileName) <> "" Then Kill TempFileName
End If
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
ActiveSheet.Protect Password:="rental"
End With
End Sub
Bookmarks