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: 1
Default SendKeys and Path Problem

Hello,

I (novice-Macro user) use a lot of fortran-compiled executables that
need a few inputs fed to them. Everything is in the same folder: the
Excel file, the executable, and the files fed to the executable. So I
created an Excel Macro that starts the executable with Shell() and then
I feed it the input files and other parameters using SendKeys(). I
have 2 problems:

1. SendKeys() is tempermental. I have found that I have to send it 2
letters at a time with a Sleep() delay so that the sending is not too
fast for the executable (I do not need the delay when I replace my
executable with say Notepad- only my executable has a pacing problem).
Is there a better way?
2. Based on an Excel cell I am taking a filename and sending it to the
Shell(). The filename refers to a file in the same directory as the
Excel file and the executable. The first time I run the program, it
crashes because it cannot find the file. If I save and close Excel
completely and then reopen Excel, the macro runs fine. I can get
around this by sending the entire path name to the executable, but
SendKeys() is slow. How can I get the Macro to know that the filename
is in the same directory as everything else? I have also tried putting
Application.DefaultFilePath=ThisWorkbook.Path' in my Workbook_Open
macro, but it does not help.

Here is a portion of my code:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As
Long)
Sub RunRunstream()
'
Dim ReturnValue As Variant
Dim rname As String
Dim i, ddelay, count As Integer
' I am not sure the following two lines do anything.
DefaultFilePath = ThisWorkbook.Path
Application.DefaultFilePath = ThisWorkbook.Path
i = 1
ddelay = Range("g10") * 1000
count = Range("h12") + 1
Do While i < count
Range("b3").Activate
rname = ActiveCell.Offset(i, 1)
' Executes Runstream.exe, pauses a little while and
' then calls the routine that sends the name.
ReturnValue = Shell(DefaultFilePath & "\Runstream", 1)
Call Sleep(ddelay)
Call SendName(i, rname, ddelay)
Range("b3").Activate
ActiveCell.Offset(i, -1) = "done"
i = i + 1
Loop
End Sub
Sub SendName(i, rname, ddelay)
DefaultFilePath = ThisWorkbook.Path
Application.DefaultFilePath = ThisWorkbook.Path
Call Sleep(ddelay)
kk = 1
' (This is why I would rather not send the path each time.)
Do While kk < Len(rname) + 2
Call Sleep(ddelay)
SendKeys Mid(rname, kk, 2), True
kk = kk + 2
Loop
Call Sleep(ddelay)
SendKeys "~", True
' Needed by the executable program.
Call Sleep(ddelay)
SendKeys "2", True
Call Sleep(ddelay)
SendKeys "~", True
Call Sleep(ddelay)
End Sub


Thanks very much,
Roger



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

 
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
Problem with leading zero's in creating a full path TUTU Excel Discussion (Misc queries) 2 May 12th 09 04:50 PM
Problem with references while opening Excel from IE using UNC path vrkorada Links and Linking in Excel 0 July 6th 07 02:53 PM
SendKeys syntax problem VBAvirgin New Users to Excel 2 January 4th 06 04:42 PM
Problem with Import Data path Barry Treadway Excel Discussion (Misc queries) 3 October 5th 05 03:05 PM
Path\File name length problem Excel Crash on save as Datasort Excel Discussion (Misc queries) 0 April 8th 05 05:19 PM


All times are GMT +1. The time now is 12:42 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"