SendKeys doesn't interact with popup window

tjdickinson

Board Regular
Joined
Jun 26, 2021
Messages
61
Office Version
  1. 365
Platform
  1. Windows
I've resorted to using SendKeys for the time being to create a PDF from my workbook using Acrobat (so the file has bookmarks). I've mapped out the key sequence:
VBA Code:
Sub exportPDF()

Workbooks(ActiveWorkbook.Name).Activate
SendKeys "%y2", True
SendKeys "c", True
SendKeys "w", True

Application.Wait (Now() + TimeValue("00:00:10"))

SendKeys "{ENTER}", True

Application.Wait (Now() + TimeValue("00:00:03"))

SendKeys "{ENTER}", True

End Sub
Three things happen:
  1. There is a long delay before opening the Create PDF window (which is done in the first two SendKeys actions); could the Application.Wait be interfering?
  2. Nothing more happens when the Create PDF pop up opens. When I ran it with debug.print, all the keystrokes were recorded. So it's sending them, but they're not being registered by the pop up window.
  3. NumLock always gets deactivated. No clue why.
I tried using Application.Wait (suggested here), Application.OnTime (suggested here), and adding a DoEvents sub (suggested here), but none of these have helped reliably. I've also tried longer wait times, but that didn't fix it.

The main issue is getting the Create PDF window to respond to the first "enter" key, and I imagine the issue will be the same when the save dialog opens. Any help is greatly appreciated. Thanks!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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