Forum

Loop Macro Through ...
 
Notifications
Clear all

Loop Macro Through Multiple Workbooks in the Same Folder

4 Posts
3 Users
0 Reactions
103 Views
(@svenis)
Posts: 1
New Member
Topic starter
 

Hi, 

I have to send the same quotes every year, but update the dates, and email them out again. I have a looping macro that updates the dates across multiple workbooks that are saved in the same folder, but I haven't figured out yet how to get a similar loop to go through that same folder to create the PDFs and emails. I started with the "Save as PDF and send email macro" from Philip from 2013 and customized it a little bit, and that's working. How can I get it to loop through multiple workbooks? What I was seeing on these forms was for looping through multiple sheets in the same workbook.

Thank you for any help you can offer!

 
Posted : 13/01/2021 10:49 pm
(@catalinb)
Posts: 1937
Member Admin
 

Hi Stephanie,
You can reuse the code you have:

With Workbooks.Open(xFdItem & xFileName)

create_and_email_pdf  '    that's all you need, this code works with the active sheet

End With

 
Posted : 15/01/2021 12:11 pm
(@svenis1)
Posts: 1
New Member
 

Thank you for your response, Catalin! That got me a little bit closer. Before I had to open the sheet myself to get the PDF and email macro to work. Now it will go to the folder and open the sheet just by me picking the folder, but it will only do the first file in the folder, then it stops. Is there a way to get it to create all the PDFs and emails within a specified folder?

 
Posted : 19/01/2021 11:04 pm
(@catalinb)
Posts: 1937
Member Admin
 

The folder dialog is there to ask you where you want to save the generated PDF, not to open all excel files from there.

You can use sample code from this topic to iterate through files in a folder and add your code to open and generate pdf: https://www.myonlinetraininghub.com/excel-forum/vba-macros/macro-written-in-32-bit-system-not-working-in-64-bit-system-win-10-and-office-2019-prof#p17458

 
Posted : 20/01/2021 2:39 am
Share: