SendKeys not working

Atroxell

Active Member
Joined
Apr 18, 2007
Messages
422
Hi,

I have the following code:

Code:
Sub get_FDR()
        TaskID = Shell("C:\Program Files\Mobius\DDR\rdswin.exe C:\temp\" & mm & dd & yy & ".msl", vbNormalFocus)
 
        Application.Wait Now + TimeValue("00:00:20")
 
        ' Close known copy of Document Direct
        AppActivate "DocumentDirect", True
        SendKeys "%{F4}", False
 
End Sub

All it does is open a program and download a file using the .msl batch instructions (created in an earlier procedure),

The code works just fine, producing the results I want. The problem lies in the last line. I just want Excel to close the "DocumentDirect" program.

The problem is, it doesn't close. What am I missing?

I am using Excel 2007.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Maybe put this is before the sendkeys statement?
Code:
Application.Wait Now + TimeValue("00:00:01")
 
Upvote 0
Hmmm...now it is closing my VBE...

Looks like I have a problem with the DocumentDirect window gaining focus.

How can I ensure that the correct window has the focus? I am assuming at this point that if I try to run this from a button on a worksheet (instead of the VBE) it will suddenly close my workbook.

Maybe I have to enumerate the open applications and try to identify it from there? I have never done that in VBA and would need some help doing so.
 
Upvote 0
I was able to get it to work. Maybe try taking the False out of the SendKeys statement? Or the "True" out of AppActivate?
 
Upvote 0
I tried all combinations of True/False, as well as omitting them for one, the other and both statements.

Same result. The VBE closes, but not DocumentDirect.
 
Upvote 0
Ok, I was able to reproduce your problem. It seems to work right when running the macro from the Excel sheet, but does not work right when running from the VBA editor. Is that the case for you too?
 
Upvote 0
Wow. Now there's a result I was not expecting.

You are correct--it works just fine when you run it off a button, but not when run from the VBE.

I am the first person in my company to attempt to use the Shell() command in VBA, and I am about to rock the world of the people I work with when they begin to understand the potential here. They spend a lot of time doing this type of batch processing manually.

Thank you so much for your help.
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,695
Members
449,117
Latest member
Aaagu

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