VBA PDF Put in Folder on Desktop

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
1,180
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Good morning,

This above my skill set. I got this code from 'http://www.tek-tips.com/viewthread.cfm?qid=1538892
and it works great. The problem is that it output the files onto the desktop (could be hundreds of files). Is there any way to modify this to output them into a folder on the desktop?

Code:
'http://www.tek-tips.com/viewthread.cfm?qid=1538892

'Tools > References > Acrobat
Sub Main()
  Dim PDDoc As Acrobat.CAcroPDDoc, newPDF As Acrobat.CAcroPDDoc
  Dim PDPage As Acrobat.CAcroPDPage
  Dim thePDF As String, PNum As Long
  Dim f As String, i As Integer, Result As Variant, NewName As String
  
  f = ThisWorkbook.Path & "\"
  thePDF = f & "transcriptgrade12.pdf"
  
  Set PDDoc = CreateObject("AcroExch.pdDoc")
  Result = PDDoc.Open(thePDF)
  If Not Result Then
    MsgBox "Can't open file: " & thePDF
    Exit Sub
  End If
  
  '...
  PNum = PDDoc.GetNumPages
  
  For i = 0 To PNum - 1
    Set newPDF = CreateObject("AcroExch.pdDoc")
    newPDF.Create
    NewName = f & " Page_" & i & "_of_" & PNum & ".pdf"
    newPDF.InsertPages -1, PDDoc, i, 1, 0
    newPDF.Save 1, NewName
    newPDF.Close
    Set newPDF = Nothing
  Next i
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Change this
Code:
f = ThisWorkbook.Path & "\"
[/B]by
f = ThisWorkbook.Path & "\folder\"
 
Upvote 0
Hey Dante!!! Thank you so much for responding to my post! That will do the trick! Originally my file was on the desktop and I wanted the files to go into the folder but your solution works if I put the file inside the folder. I'll take it! Thanks again. I appreciate it!! Have a great day!
 
Upvote 0
With pleasure, Thank you for the comments and also that you have an excellent day.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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
Back
Top