Re: Combine PDF Documents into one document and attach to an email
you can close
Re: Combine PDF Documents into one document and attach to an email
you can close
Re: Combine PDF Documents into one document and attach to an email
sorry
Dear all
Attached form has a User form that opens automatically when you open it, on the big list (ListView1) you can multi select the lines by holding CTRL key down + clicking mouse right button, It will highlight the selected lines then when you click the "Select Invoices" button it will list the selected invoices on the small window (ListView2) at the top. From here when you click the "Multiple Attach" button it will find each selected invoices' directory path at the excel Sheet("Multi") Colum F then convert each of the founded invoices to PDF and one by one it will attach these PDF invoices to one email.
What I am trying to achieve is merge all the PDF invoices into one document then attach that document to the email. Can this be done?
Thanks in advance
Re: Attach multiple documents on one email by using document path
how much I thank you it wont be enough Pike, as I said you have solved a massive issue that I was trying to solve many, many months. It attaches 22 invoices in PDF format in one click.
thank you very much again. Respect
Re: Attach multiple documents on one email by using document path
Thank you pike, it worked perfectly ,many many months' hard work paid off finally thanks to you.
obviously if the range increased I need to increase the B2:B4 range. Would it be possible to do until the blank cell in B?
Also it work so slow, is there way to speed it up?
Kind regards
Re: Attach multiple documents on one email by using document path
still not finalised yet, if someone help with my last question it will be done then
Re: Attach multiple documents on one email by using document path
Hi All
Finally I have cracked this problem and managed to attach more one than one file on an email (I didn't know it is this easy), the only problem I have is I had to point the exact cell number that had the path address. Is that a way that I can generalise the cell rather than saying B2,B3,B4,B5 ...ect? I want the macro see every cell path in Colum B until the empty cell and attach it to the email as PDF. Can you please help me on that?
Sub AttachMultiFiles()
Dim inv As String, invPDF As String
Dim inv2 As String, inv2PDF As String
Dim inv3 As String, inv3PDF As String
'S = Stored location
'FOR INVOICE 1
S = Worksheets("Sheet1").Range("B2").Value
MyFilePath = S
'PDF convert
inv = MyFilePath
invPDF = TempPDF(inv)
MakeWordPDFFile inv, invPDF
'FOR INVOICE 2
S = Worksheets("Sheet1").Range("B3").Value
MyFilePath2 = S
'PDF convert
inv2 = MyFilePath2
inv2PDF = TempPDF(inv2)
MakeWordPDFFile inv2, inv2PDF
'FOR INVOICE 3
S = Worksheets("Sheet1").Range("B4").Value
MyFilePath3 = S
'PDF convert
inv3 = MyFilePath3
inv3PDF = TempPDF(inv3)
MakeWordPDFFile inv3, inv3PDF
'Create e-mail item
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.BodyFormat = olFormatHTML
.HTMLBody = "Here is the file you asked for"
.Attachments.Add invPDF
.Attachments.Add inv2PDF
.Attachments.Add inv3PDF
.Display
End With
End Sub
Display More
thanks
Re: Attach multiple documents on one email by using document path
Hi all again
Looks like no one will be able to solve my problem on this, I like to approach it differently, is there a way that I can do this by going into the directory and picking the individual invoices regarding the requested invoice number then attaching it as PDF on to one email
For example ; “ \\SVR-Storage4\Accounts_Data\CM-Docs\B\P\1\BP1\214\Billref 245680_513897_1.docx “ this directory link can be broken down as C:\\SVR-Storage4\AccountsData\CM-Docs\ B is first letter of the client code and P is the second letter of the client code these 2 letter are folders by itself ,1 is the first number of the client code (this can be 2 or 3 numbers sometimes) this is also a folder , when whole of these folders selected it gives you another folder BP1 which contains the various matters under this client code , on this incident matter folder is 214 where the Bill ref 245680 is stored, the rest of the number is not needed.
I have seen on some other forums that people managed to attach multiple documents by selecting the directory. Would it be possible to write a code which will pick up the invoice from the directory rather than the document path option (Colum F) as the document path option hasn’t worked?
Thank you for your time
Re: Attach multiple documents on one email by using document path
Hi Apo , thank you for getting back to me , I didn't realise you replied my post. I still not managed to solve this problem.
I have created another Listview window which I called Listview2. From the first Listview window I select multiple rows then with click of a button I list the selected invoices to another sheet which I call "Multi".
These selected invoices appear on Listview2 window with below code I try to attach selected rows' invoices to one email but still doesn't work. Could someone help me please?
Private Sub MultipleAttach_Click()
Dim R As Range, fnd As Range, fn As String, fnPDF As String
Dim Ref1 As Long
Dim StrSignature As String
Dim sPath As String
Dim EmailBody As String
Dim OutApp As Object
Dim OutMail As Object
Dim strBody As String
sPath = "C:\Users\" & Environ("username") & "\AppData\Roaming\Microsoft\Signatures\Signature.htm"
If Dir(sPath) <> "" Then
StrSignature = GetSignature(sPath)
Else
StrSignature = ""
End If
On Error Resume Next
Set R = Worksheets("Multi").Range("E2", _
Worksheets("Multi").Range("E" & Rows.Count).End(xlUp))
For i = 1 To ListView2.ListItems.Count
' If ListView2.ListItems(i).Checked = True Then
If ListView2.ListItems(i).Selected = True Then
SearchInv = ListView2.ListItems(i).SubItems(5)
With R
.NumberFormat = "0"
.Value = .Value
Set fnd = .Find(SearchInv.Value, LookAt:=xlWhole)
End With
If Not fnd Is Nothing Then
Unload Me
fn = fnd.Offset(, 1).Value
fnPDF = TempPDF(fn)
MakeWordPDFFile fn, fnPDF
Else: MsgBox "Number not found!"
End If
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
Ref1 = SearchInv.Value
strBody = ""
End If
Next
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "Payment Reminder for Invoice No : " & Ref1
.Body = "Dear Sir" _
& vbCrLf & "" _
& vbCrLf & "Our records is showing that we haven't received payment for our Invoice No: " & Ref1 _
& vbCrLf & "" _
& vbCrLf & "I will be grateful if you arrange payment against this invoice " _
& vbCrLf & ""
.Attachments.Add fnPDF
.HTMLBody = strBody & .HTMLBody & StrSignature
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
UserForm1.Show
'ThisWorkbook.RefreshAll
End Sub
Display More
this is liestview2 pic
[ATTACH=CONFIG]68772[/ATTACH]
This is sheet Multi
[ATTACH=CONFIG]68774[/ATTACH]
this part of the code should make it work but when code run nothing happens
Set R = Worksheets("Multi").Range("E2", _
Worksheets("Multi").Range("E" & Rows.Count).End(xlUp))For i = 1 To ListView2.ListItems.Count
' If ListView2.ListItems(i).Checked = True Then
If ListView2.ListItems(i).Selected = True Then
SearchInv = ListView2.ListItems(i).SubItems(5)
With R
.NumberFormat = "0"
.Value = .Value
Set fnd = .Find(SearchInv.Value, LookAt:=xlWhole)
End With
Re: Attach multiple documents on one email by using document path
can anyone help on this ?:jumpupdo:
Dear all
I'm using the code below, in outlook vba, It converts the File path link to PDF then creates an email, attach a file, and send the email. It works fine, except I can't figure out how to add multiple attachments to a single email?
My File path is in Column F under Sheet1 as below. Every line relates one document in directory. Here is the sample lines ;
\\SVR-Storage4\Accounts_Data\CM-Docs\B\P\1\BP1\214\Bill ref 245680_513897_1.docx
\\SVR-Storage4\Accounts_Data\CM-Docs\C\H\A\CHA116\31\Bill ref 245675_513831_1.docx
\\SVR-Storage4\Accounts_Data\CM-Docs\C\I\T\CIT13\312\Bill ref 245668_513786_1.docx
\\SVR-Storage4\Accounts_Data\CM-Docs\C\O\F\COFW6\715\Bill ref 245669_513787_1.docx
\\SVR-Storage4\Accounts_Data\CM-Docs\H\T\L\HTL1\288\Bill ref 245674_513812_1.docx
\\SVR-Storage4\Accounts_Data\CM-Docs\H\T\L\HTL1\303\Bill ref 245673_513810_1.docx
\\SVR-Storage4\Accounts_Data\CM-Docs\L\E\W\LEW23\22\Bill ref 245681_513898_1.docx
The way it works at the moment ; when you open the excel form it automatically opens a UserForm which has Listview window. if you highlight a row it updates the various TextBoxes over the UserForm, TextBox5 has the invoice number, when you click "Email button" on the UserForm, it finds the whatever invoice number in the TextBox5 and matches with the invoice number under Column B on "invoice Sheet" then activates the path under Column E. The File path will find the invoice in the directory in word format then it will convert it to PDF and attach to an email.
For multiple attachment I have crated another Sheet which is Sheet1. On the UserForm Listview window I select multiple rows then I click "List" button this will create a list on the Sheet1 for multiple attachments. You should also select multiple invoices on the UserForm list then click "List" button it will create multiple list on the Sheet1 for emailing to see the list
So what is the best way to achieve by amending below code and get multiple PDF invoice on one email?
Any help is greatly appreciated.
Private Sub EmailInvoice_Click()
Dim R As Range, fnd As Range, fn As String, fnPDF As String
Dim Ref1 As Long
Dim StrSignature As String
Dim sPath As String
Dim EmailBody As String
Dim OutApp As Object
Dim OutMail As Object
Dim strBody As String
sPath = "C:\Users\" & Environ("username") & "\AppData\Roaming\Microsoft\Signatures\Signature.htm"
If Dir(sPath) <> "" Then
StrSignature = GetSignature(sPath)
Else
StrSignature = ""
End If
On Error Resume Next
Set R = Worksheets("invoice").Range("B2", _
Worksheets("invoice").Range("B" & Rows.Count).End(xlUp))
With R
.NumberFormat = "0"
.Value = .Value
Set fnd = .Find(TextBox5.Value, LookAt:=xlWhole)
End With
If Not fnd Is Nothing Then
Unload Me
fn = fnd.Offset(, 3).Value
fnPDF = TempPDF(fn)
MakeWordPDFFile fn, fnPDF
Else: MsgBox "Number not found!"
End If
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
Ref1 = TextBox5.Value
strBody = ""
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "Payment Reminder for Invoice No : " & Ref1
.Body = "Dear Sir" _
& vbCrLf & "" _
& vbCrLf & "Our records is showing that we haven't received payment for our Invoice No: " & Ref1 _
& vbCrLf & "" _
& vbCrLf & "I will be grateful if you arrange payment against this invoice " _
& vbCrLf & ""
.Attachments.Add fnPDF
.HTMLBody = strBody & .HTMLBody & StrSignature
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
UserForm1.Show
'ThisWorkbook.RefreshAll
End Sub
Function GetSignature(fPath As String) As String
Dim fso As Object
Dim TSet As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set TSet = fso.GetFile(fPath).OpenAsTextStream(1, -2)
GetSignature = TSet.ReadAll
TSet.Close
End Function
Private Sub PDFConvertor_Click()
Dim R As Range, fnd As Range, fn As String, fnPDF As String
On Error Resume Next
Set R = Worksheets("invoice").Range("B2", _
Worksheets("invoice").Range("B" & Rows.Count).End(xlUp))
With R
.NumberFormat = "0"
.Value = .Value
Set fnd = .Find(TextBox5.Value, LookAt:=xlWhole)
End With
If Not fnd Is Nothing Then
Unload Me
fn = fnd.Offset(, 3).Value
fnPDF = TempPDF(fn)
MakeWordPDFFile fn, fnPDF
ThisWorkbook.FollowHyperlink fnPDF
Else: MsgBox "Number not found!"
End If
UserForm1.Show
'ThisWorkbook.RefreshAll
End Sub
Display More
Re: Column Y has invoice hyperlink , transfer the link to PDF and attache to an ema
Can anyone help please?
Quote from Lapot;730175I have also this code to attach the invoices as word document in to an email but I like the invoices attached as PDF.
CodeDisplay MoreSub datesexcelvba() Dim myApp As Outlook.Application, mymail As Outlook.MailItem Dim mydate1 As Date Dim mydate2 As Long Dim datetoday1 As Date Dim datetoday2 As Long Dim Ref1 As Long Dim example As Range Set example = Range("T:T,U:U,W:W,X:X") Dim fnd As Range Dim attachment As String Dim x As Long example.ClearContents LastRow = Sheets("Rapor").Cells(Rows.Count, 1).End(xlUp).Row For x = 2 To LastRow attachement = Sheets("Rapor").Cells(x, 25).Value Ref1 = Cells(x, 5).Value mydate1 = Cells(x, 4).Value mydate2 = mydate1 Cells(x, 20).Value = mydate2 datetoday1 = Date datetoday2 = datetoday1 Cells(x, 21).Value = datetoday2 If mydate2 - datetoday2 < 3 Then Set myApp = New Outlook.Application Set mymail = myApp.CreateItem(olMailItem) mymail.To = Cells(x, 22).Value With mymail .Subject = "Payment Reminder" .Body = "Dear Sir" _ & vbCrLf & "" _ & vbCrLf & "Our records is showing that we havent recived payment for our Invoice No: " & Ref1 _ & vbCrLf & "" _ & vbCrLf & "I will be greatful if you arrange payment aginst this invoice" _ & vbCrLf & "" _ & vbCrLf & "Kind Regards" _ & vbCrLf & "John Smith" _ & vbCrLf & "" _ & vbCrLf & "" .Attachments.Add attachement .Display '.Send Cells(x, 23) = "Yes" Cells(x, 23).Interior.ColorIndex = 3 Cells(x, 23).Font.ColorIndex = 2 Cells(x, 23).Font.Bold = True Cells(x, 24).Value = mydate2 - datetoday2 End With If mydate2 - datetoday2 >= 3 Then Cells(x, 23) = "No" Cells(x, 23).Interior.ColorIndex = 5 Cells(x, 23).Font.ColorIndex = 6 Cells(x, 23).Font.Bold = True Cells(x, 24).Value = mydate2 - datetoday2 Set mymail = Nothing End If End If Next Set myApp = Nothing Set mymail = Nothing End Sub
Re: Column Y has invoice hyperlink , transfer the link to PDF and attache to an ema
I have also this code to attach the invoices as word document in to an email but I like the invoices attached as PDF.
Sub datesexcelvba()
Dim myApp As Outlook.Application, mymail As Outlook.MailItem
Dim mydate1 As Date
Dim mydate2 As Long
Dim datetoday1 As Date
Dim datetoday2 As Long
Dim Ref1 As Long
Dim example As Range
Set example = Range("T:T,U:U,W:W,X:X")
Dim fnd As Range
Dim attachment As String
Dim x As Long
example.ClearContents
LastRow = Sheets("Rapor").Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To LastRow
attachement = Sheets("Rapor").Cells(x, 25).Value
Ref1 = Cells(x, 5).Value
mydate1 = Cells(x, 4).Value
mydate2 = mydate1
Cells(x, 20).Value = mydate2
datetoday1 = Date
datetoday2 = datetoday1
Cells(x, 21).Value = datetoday2
If mydate2 - datetoday2 < 3 Then
Set myApp = New Outlook.Application
Set mymail = myApp.CreateItem(olMailItem)
mymail.To = Cells(x, 22).Value
With mymail
.Subject = "Payment Reminder"
.Body = "Dear Sir" _
& vbCrLf & "" _
& vbCrLf & "Our records is showing that we havent recived payment for our Invoice No: " & Ref1 _
& vbCrLf & "" _
& vbCrLf & "I will be greatful if you arrange payment aginst this invoice" _
& vbCrLf & "" _
& vbCrLf & "Kind Regards" _
& vbCrLf & "John Smith" _
& vbCrLf & "" _
& vbCrLf & ""
.Attachments.Add attachement
.Display
'.Send
Cells(x, 23) = "Yes"
Cells(x, 23).Interior.ColorIndex = 3
Cells(x, 23).Font.ColorIndex = 2
Cells(x, 23).Font.Bold = True
Cells(x, 24).Value = mydate2 - datetoday2
End With
If mydate2 - datetoday2 >= 3 Then
Cells(x, 23) = "No"
Cells(x, 23).Interior.ColorIndex = 5
Cells(x, 23).Font.ColorIndex = 6
Cells(x, 23).Font.Bold = True
Cells(x, 24).Value = mydate2 - datetoday2
Set mymail = Nothing
End If
End If
Next
Set myApp = Nothing
Set mymail = Nothing
End Sub
Display More
I have a excel sheet which has Hyperlink on Column Y to open invoices in word document. I like to run a macro and open the invoice from the link convert to PDF and attach to an email.
Below code is for the invoice named MyReport.docx on desktop , so I like to change this code so that invoices comes from Column Y on Excel sheet.
Is it possible?
Sub AttachActiveSheetPDF_03()
' Copy this code to the module of any Excel's workbook.
' Prepare report/invoice in MyReport.doc or MyReport.docx and store it on Desktop
' This macro exports the report document to PDF and attaches that PDF to Outlook's email
Dim IsOutlCreated As Boolean, IsWordCreated As Boolean, IsDocOpen As Boolean
Dim DesktopPath As String, DocFile As String, PdfFile As String, Title As String, s As String
Dim OutlApp As Object, WordApp As Object
Dim i As Long
Dim char As Variant
Const wdExportFormatPDF = 17
' --> Settings, change to suit
Const WordDocument = "MyReport.doc"
'Title = Range("A1") & " " & Date
Title = "PU: " & Date
' <-- End ofsettings
' Check WordDocument presence on Desktop
DesktopPath = CreateObject("Wscript.Shell").SpecialFolders("Desktop")
DocFile = DesktopPath & "\" & WordDocument
s = Dir(DocFile & "*")
If s = "" Then
MsgBox "Word Report file not found:" & vbLf & DocFile, vbExclamation, "Exit"
Exit Sub
End If
DocFile = DesktopPath & "\" & s
' Define PDF filename in TEMP folder
PdfFile = WordDocument
i = InStrRev(PdfFile, ".", , vbTextCompare)
If i > Len(PdfFile) - 6 Then PdfFile = Left(PdfFile, i - 1)
For Each char In Split("? "" / \ < > * | :")
PdfFile = Replace(PdfFile, char, "_")
Next
PdfFile = Left(CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2) & "\" & PdfFile, 251) & ".pdf"
'Debug.Print PdfFile
' Delete PDF file - for the case it was not deleted at debugging
If Len(Dir(PdfFile)) Then Kill PdfFile
' Open WordDocument if it was not open previously
On Error Resume Next
Set WordApp = GetObject(, "Word.Application")
If Err Then
Set WordApp = CreateObject("Word.Application")
IsWordCreated = True
End If
Err.Clear
WordApp.ScreenUpdating = False
With WordApp.Documents(s): End With
IsDocOpen = Err = 0
On Error GoTo 0 'exit_
If Not IsDocOpen Then
WordApp.Documents.Open Filename:=DocFile, ReadOnly:=IsWordCreated
End If
' Export activedocument as PDF to the temporary folder
WordApp.Documents(s).ExportAsFixedFormat OutputFileName:=PdfFile, ExportFormat:=wdExportFormatPDF
' Use already open Outlook if possible
On Error Resume Next
Set OutlApp = GetObject(, "Outlook.Application")
If Err Then
Set OutlApp = CreateObject("Outlook.Application")
IsOutlCreated = True
End If
On Error GoTo 0
' Prepare e-mail with PDF attachment
With OutlApp.CreateItem(0)
' Prepare e-mail
.Subject = Title
'.To = "..." ' <-- Put email of the recipient here
'.CC = "..." ' <-- Put email of 'copy to' recipient here
.Body = "Hi," & vbLf & vbLf _
& "The invoice is attached in PDF file" & vbLf & vbLf _
& "Best Regards," & vbLf _
& Application.UserName & vbLf & vbLf
.Attachments.Add PdfFile
' Try to send
On Error Resume Next
'.Send ' or use
.Display
' Return focus to Excel's window
Application.Visible = True
If Err Then
MsgBox "E-mail was not sent", vbExclamation
' Else
'MsgBox "E-mail successfully sent", vbInformation
End If
On Error GoTo 0
End With
exit_:
' Delete the temporary PDF file
If Len(Dir(PdfFile)) Then Kill PdfFile
' Close WordDocument if it was open via this macro
If IsDocOpen Then
WordApp.Documents(s).Close False
Else
WordApp.ScreenUpdating = True
End If
' Close WordApp if it was open via this macro
If IsWordCreated Then WordApp.Quit: Set WordApp = Nothing
' Try to quit Outlook if it was not previously open
If IsOutlCreated Then OutlApp.Quit
' Release the memory of object variable
' Note: sometimes Outlook object can't be released from the memory
Set OutlApp = Nothing
If Err Then MsgBox Err.Description, vbCritical, "Error #" & Err.Number
End Sub
Display More
Re: Copying formula on a colum and paste as value
Quote from JohnCleary;729883
thank you very much , perfect
Dear all
I have a sheet that Column B contains variable data which are formula based, I am trying to copy the values from Column B and paste it to Column C. My Sheet has header on row1 so header will be static.
Tried various ways but I cant get what I like. I don't want to use record macro option as the data length keep changing.
Your views will be appreciated.
Kind regards