VBA Merge PDFs with Similar File Name

Chrisjschndr

New Member
Joined
May 10, 2022
Messages
10
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Mobile
I have a macro that will scroll through a range and fill in a form and then export that as PDF to the folder that the Excel file is in. The macro adds "TB" to the end of the file name - the TB means it is basically a cover page. I then paste all the regular files in the folder. This part all works perfect. I need one more part though to complete my automation cycle.

How do I write the VBA to use Acrobat to add the TB to the front of the other file? I found the other posts that had the code to initialize Acrobat, but really need to know how to loop through the folder. I plan on using Adobe but don't have it on the computer this screenshot is from - just ignore the Foxit part of the screenshot.

Any help is much appreciated.


VBA Merge PDFs of Similar Name.jpg
 

Chrisjschndr

New Member
Joined
May 10, 2022
Messages
10
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Mobile
So it got through picking the folder, and then I think it just got to the end without actually doing anything. The "done" message popped up, but nothing was converted. The step thru got passed the folder part but seems like it skipped all the other steps.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
7,541
Step through the code by pressing the F8 key in the VBA editor and see if it is finding each " TB" cover page PDF and its corresponding main PDF. It should if the file names look like the ones in your OP.

To help debug the problem add these lines at the appropriate places in the code:

VBA Code:
        MsgBox FSfile.Path

VBA Code:
        MsgBox PDFmainFile
 

Chrisjschndr

New Member
Joined
May 10, 2022
Messages
10
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Mobile
Ok I put in MsgBoxs and nailed it down to the line:

For Each FSfile In(PDFsFolder).Files

A MsgBox popped up the line before but not after this line.

Of course it was filepath not found.
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
7,541
Of course it was filepath not found.
That error doesn't make sense because in your previous reply you said it got to the end and displayed "Done" and the only change since then is to add the MsgBox lines. Please post your code.

Also, try it with the files in a local folder, not in a OneDrive folder.
 

Chrisjschndr

New Member
Joined
May 10, 2022
Messages
10
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Mobile
Thanks for all the help John, I really appreciate it. The OneDrive folder comes default with my windows setup and I wasn't sure how easy I would be able to get that done. Adobe was also giving me problems insisting I didnt have an active account that I did have and was paying for (which was very frustrating). I really was having problems narrowing down the problem when new ones starting like this were popping up. I ended up getting what I needed done in Python using PyPDF2 with much less code.
 

Forum statistics

Threads
1,176,013
Messages
5,900,883
Members
434,857
Latest member
lowiscoetzee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top