Hello all,
I am hoping you can help me with my issue. I have created a few macros now that create an email message with attachments when I have the file name pointed to a specific source (or cell value). But I am trying to write a marco to insert file names based on a formula that is returned into multiple cells. I have a form that someone will fill out and the vaule I am trying to extract is an invoice number. The number maybe unique or repeated multiple times depending on the situation.
I have created the following formula to get a list of unique values in the cells.
=IFERROR(IF(INDEX('Fill Form'!$E$22:$E$27,MATCH(0,INDEX(COUNTIF($T$11:T11,'Fill Form'!$E$22:$E$27),),0))=0,"",INDEX('Fill Form'!$E$22:$E$27,MATCH(0,INDEX(COUNTIF($T$11:T11,'Fill Form'!$E$22:$E$27),),0))),"")
My goal is to attach files in an email, using the output of this formula to start the reference of the file name I want to insert. I have this formula outputing to 6 cells (because that is currently the maximum number of values that can be input), and I may have less unique values than the maximum of 6. I can write code to reference each of the 6 cells to as the start of the file name, but my concern is that the macro will break when I refer to a cell that does not have a value in it.
This is what I have written for code so far.
On Error GoTo ErrHandler
Sheets("Approval Form").Select
Dim Path As String
Dim filename1 As String
Dim Path2 As String
Dim filname2 As String
Dim Path3 As String
Dim
Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")
Dim objEmail As Object
Set objEmail = objOutlook.CreateItem(olMailItem)
Path = Sheets("Fill Form").Range("T6").Value
filename1 = Sheets("Fill Form").Range("T4").Value
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Path & "APPROVAL for" & filename1 & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=True
With objEmail
.To = Sheets("Fill Form").Range("T9")
.CC = Sheets("Fill Form").Range("T8")
.Subject = Sheets("Fill Form").Range("T4") & " APPROVAL NEEDED"
.Body = "Hello," & vbNewLine & vbNewLine & "Please see attached approval forms for the following vendor invoices:" & vbNewLine & vbNewLine & Sheets("Fill Form").Range("T12") & vbNewLine & Sheets("Fill Form").Range("T13") & vbNewLine & Sheets("Fill Form").Range("T14") & vbNewLine & Sheets("Fill Form").Range("T15") & vbNewLine & Sheets("Fill Form").Range("T16") & vbNewLine & Sheets("Fill Form").Range("T17") & vbNewLine & vbNewLine & "Thank You"
.Attachments.Add (Path & filename1 & ".pdf")
.Display
End With
ErrHandler:
Any help is greatly appreciated!
I am hoping you can help me with my issue. I have created a few macros now that create an email message with attachments when I have the file name pointed to a specific source (or cell value). But I am trying to write a marco to insert file names based on a formula that is returned into multiple cells. I have a form that someone will fill out and the vaule I am trying to extract is an invoice number. The number maybe unique or repeated multiple times depending on the situation.
I have created the following formula to get a list of unique values in the cells.
=IFERROR(IF(INDEX('Fill Form'!$E$22:$E$27,MATCH(0,INDEX(COUNTIF($T$11:T11,'Fill Form'!$E$22:$E$27),),0))=0,"",INDEX('Fill Form'!$E$22:$E$27,MATCH(0,INDEX(COUNTIF($T$11:T11,'Fill Form'!$E$22:$E$27),),0))),"")
My goal is to attach files in an email, using the output of this formula to start the reference of the file name I want to insert. I have this formula outputing to 6 cells (because that is currently the maximum number of values that can be input), and I may have less unique values than the maximum of 6. I can write code to reference each of the 6 cells to as the start of the file name, but my concern is that the macro will break when I refer to a cell that does not have a value in it.
This is what I have written for code so far.
On Error GoTo ErrHandler
Sheets("Approval Form").Select
Dim Path As String
Dim filename1 As String
Dim Path2 As String
Dim filname2 As String
Dim Path3 As String
Dim
Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")
Dim objEmail As Object
Set objEmail = objOutlook.CreateItem(olMailItem)
Path = Sheets("Fill Form").Range("T6").Value
filename1 = Sheets("Fill Form").Range("T4").Value
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Path & "APPROVAL for" & filename1 & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=True
With objEmail
.To = Sheets("Fill Form").Range("T9")
.CC = Sheets("Fill Form").Range("T8")
.Subject = Sheets("Fill Form").Range("T4") & " APPROVAL NEEDED"
.Body = "Hello," & vbNewLine & vbNewLine & "Please see attached approval forms for the following vendor invoices:" & vbNewLine & vbNewLine & Sheets("Fill Form").Range("T12") & vbNewLine & Sheets("Fill Form").Range("T13") & vbNewLine & Sheets("Fill Form").Range("T14") & vbNewLine & Sheets("Fill Form").Range("T15") & vbNewLine & Sheets("Fill Form").Range("T16") & vbNewLine & Sheets("Fill Form").Range("T17") & vbNewLine & vbNewLine & "Thank You"
.Attachments.Add (Path & filename1 & ".pdf")
.Display
End With
ErrHandler:
Any help is greatly appreciated!