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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

oliquino

New Member
Joined
Apr 16, 2020
Messages
9
Office Version
  1. 2016
  2. 2013
  3. 2010
Platform
  1. Windows
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: 3

jkpieterse

Well-known Member
Joined
Dec 3, 2007
Messages
1,102
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
 

Watch MrExcel Video

Forum statistics

Threads
1,132,686
Messages
5,654,750
Members
418,150
Latest member
Yerraashok

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