Application.SendKeys

oliquino

New Member
Joined
Apr 16, 2020
Messages
9
Office Version
  1. 2016
  2. 2013
  3. 2010
Platform
  1. Windows
Somehow finding difficult to activate Application.SendKeys NewPDFFile, True and cant insert/code the path file name to be use on the save as dialog box.

If .Range("H" & StudentRow).Value = Empty Then
StudentName = .Range("A" & StudentRow).Value 'Student Name

NewPDFFile = ThisWorkbook.Path & "\" & StudentName & "_Enrollment.pdf" 'New File Name
If Dir(NewPDFFile, vbDirectory) <> "" Then Kill (NewPDFFile) 'Deleted File if exists

Application.SendKeys "^+(s)", False
Application.Wait Now + 0.00001
Application.SendKeys NewPDFFile, True
Application.Wait Now + 0.00003
Application.SendKeys "%(s)" 'SAve As
Application.Wait Now + 0.00002


Appreciate any solution. Thanks
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
apologies as im new and not so familiar with the language used.

Im trying to save a file however it doesn't proceed on changing on the desired pdf file name on the save as dialog box.

Application.SendKeys NewPDFFile, True

NewPDFFile = ThisWorkbook.Path & "\" & StudentName & "_Enrollment.pdf" 'New File Name
If Dir(NewPDFFile, vbDirectory) <> "" Then Kill (NewPDFFile) 'Deleted File if exists
 

Attachments

  • PDF.JPG
    PDF.JPG
    35.7 KB · Views: 5
Upvote 0
If you record a macro to export a sheet to PDF, you end up with this code:
VBA Code:
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "C:\Users\XXX\Documents\TestPDP.pdf", Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
        False
So just replace the hard-coded path and file name with your variable:
VBA Code:
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        NewPDFFile, Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
        False
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,797
Members
449,048
Latest member
greyangel23

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