Activate already open PDF

buzz71023

Active Member
Joined
May 29, 2011
Messages
295
Office Version
  1. 2016
Platform
  1. Windows
I have a program that automatically generates a Excel .CSV file and a PDF file of some data. The CSV file and the worksheet name have the same name as the name of the PDF. For instance, if the CSV name is MyDatabase123 then the worksheet name will also be MyDatabase123, this is the same name as the PDF. The only difference in the two is the file extension. The user is supposed to have both the CSV and the PDF open at the same time.
Is there a way to have Excel activate the PDF and save to the certain file path (P:\Job Packets)?


VBA Code:
Sub Button1_Click()
Dim CurrFileName As String, PDFname As String, NewFileName As String

CurrFileName = ActiveSheet.Name
PDFname = CurrFileName + ".pdf"
NewFileName = Range("D6")

Windows(PDFname).Activate

'Save PDF as NewFileName

End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
You may not need to activate the PDF file. The file is already on disk somewhere, right? Try this:

VBA Code:
'replace Windows(PDFname).Activate with the following line. Replace the path with your choice.

Call Shell("C:\test\" & CurrFileName & ".pdf D:\test\" & Range("D6").value)

*I have not tried it.
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,956
Latest member
JPav

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