I need Outlook VBA to sendkeys to an open doc in Acrobat Reader....

ARiles

New Member
Joined
Mar 28, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I written a Sub/Script for Outlook to print 2 copies of an attached PDF. I now need to get Outlook VBA to send keys (Select all, Copy and Close..."^A", "^C", "^W") to the already open PDF in AcrobatReader.

I have tried all the standard methods and none have worked. See below:

Version 1:

Dim xAcrobat As Variant
xAcrobat = Shell("C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe", vbNormalFocus)
AppActivate xAcrobat
Application.wait (Now() + TimeValue("00:00:01"))
Application.SendKeys "{^A}", True
Application.SendKeys "{^C}", True
Application.SendKeys "{^W}", True

Version 2:

Shell "C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe", vbNormalFocus
SendKeys "^A", True
SendKeys "^C", True
SendKeys "^W", True

Outlook does not seem to send the keystrokes to acrobat.

The end goal is to have the copied text from the PDF be run in an excel workbook I created to use that text to create and print "audit sheets" we use for our manufacturing process.

Any help would be appreciated.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Welcome to the forum.

This worked for me using Excel. No braces, also not caps on A, C, W. With caps, it didn't work. My PDF file started with "2021-01", so that is why my AppActivate has that. I already had Adobe open, so I didn't need to include the Shell command like you did.

After the PDF closed, I opened Notepad and successfully pasted the text from the PDF.

VBA Code:
    AppActivate "2021-01"
    Application.Wait (Now() + TimeValue("00:00:01"))
    Application.SendKeys "^a", True
    Application.SendKeys "^c", True
    Application.SendKeys "^w", True
 
Upvote 0
Welcome to the forum.

This worked for me using Excel. No braces, also not caps on A, C, W. With caps, it didn't work. My PDF file started with "2021-01", so that is why my AppActivate has that. I already had Adobe open, so I didn't need to include the Shell command like you did.

After the PDF closed, I opened Notepad and successfully pasted the text from the PDF.

VBA Code:
    AppActivate "2021-01"
    Application.Wait (Now() + TimeValue("00:00:01"))
    Application.SendKeys "^a", True
    Application.SendKeys "^c", True
    Application.SendKeys "^w", True
Thanks for the reply. You are correct that method works great in Excel. My problem is it does not work in Outlook at all. I wonder if there is some "security" feature that Microsoft placed in Outlook to keep it from doing the "sendkeys".
 
Upvote 0
Outlook's object model does not have sendkeys.
 
Upvote 0
AS above, Outlooks object model does not allow for SendKeys, but you could always use the WScript COM Object ( as below). The following example assumes you are running the code from the VBIDE, and will first SendKeys the shortcut to put the cursor in the Immediate Window. It will pause 2 seconds, and then it will use SendKeys to type "Hello World". Hope this helps.

VBA Code:
Sub NewSendKeys()
    Dim WSHShell  As Object
    Set WSHShell = CreateObject("WScript.Shell")
    Pause 1
    WSHShell.SendKeys "^g"
    Pause 2
    WSHShell.SendKeys "Hello World"
    Set WSHShell = Nothing
End Sub
Sub Pause(Optional ByVal Period As Single = 2)
    Period = Period + Timer
    Do
        DoEvents
    Loop Until Period < Timer
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,174
Members
452,615
Latest member
bogeys2birdies

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