LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default SendKeys with DOS program

Hi all,

Please help as I'm going INSANE.......................................

I have written a VBA macro in Excel, which attempts to do the following:
1. Loop through spreadsheets in a directory
- Create a text input file from data held in spreadsheet.
- Open a DOS program with the SHELL command
- Send name of this input file to the DOS program
- Retrieve data from the output file, and paste into spreadsheet
- Save and close spreadsheet, open next spreadsheet in directory.

The SendKeys command is failing on what appears to be hundreds of different
fronts:-

I have tried to activate the DOS program with :-
retval = Shell("DOS_Program.exe, 1)
AppActivate retval, True

This yields errors, so from this forum I have tried :-
On Error Resume Next
Do
Err.Clear
AppActivate retval, True
Loop Until Err.Number = 0

I have tried wrapping every SendKeys statement with :-
retval = DoEvents()
SendKeys string_Filename & "{ENTER}", True
retval = DoEvents()

I have also tried adding manual delays, to try and ensure the keys are being
sent to the correct application :-
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 2
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
(and have tried varying the delay here from 1 to 10 seconds)

The errors I am getting vary, but tend to involve the following:-
- Command Prompt windows staying open, with an empty command line
- Command Prompt window stays open with incorrect filename and no enter key
- Macro attempting to close itself, i.e. not one of the processed
spreadsheets.

I have done a similar task in the past, i.e. batch processing DOS based
programs that don't have a command line option, using the Windows Script
Host. Remembering back, I had to play about with the delay to get the DOS
program to successfully accept the SendKeys and run the file.
In this case though, I need to use VBA from within EXCEL, and not externally
using VBScript.

ANY IDEAS OR HELP PLEASE BEFORE I SHOOT MYSELF ;-)

p.s. All files and the DOS program are stored in the same sub-directory to
the spreadsheet holding the macro code.
--
Cheers,

Paul.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sendkeys Jim Excel Programming 1 April 16th 05 06:44 PM
Inter-program communication using SendKeys Tim Coddington Excel Programming 3 October 7th 04 04:00 AM
SendKeys command not focusing on the correct open program mjwillyone[_12_] Excel Programming 0 December 30th 03 04:06 AM
merging excel program with tdc finance program judy Excel Programming 0 November 5th 03 08:01 PM
SendKeys Ron de Bruin Excel Programming 3 August 25th 03 10:21 PM


All times are GMT +1. The time now is 04:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"