Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

wait for outside application 1

Status
Not open for further replies.

andrew299

Technical User
Nov 18, 2002
140
GB
I know there are loads of previous posts on this but I cant find any that i can apply/understand

I am running a macro in excel, but half way through I need to run an exe file in C to retrieve a text file to do some fancy stuff and produce a name that my macro can use. The user specifies the text file.

To pause it I have simply put in a msgbox that asks if the file has been selected. This stops the code running away with itself.

But it is not very eloquent and would rather no user interaction to do this. Also I cant rely on a wait for 5 seconds function for example because the user may be too slow.

Has any one got any ideas?

code is simply -

msgbox - do you want to extract a file (yes/no)

yes - go to seperate sub and run C++ program

have you selected file (yes/no)


no - assumes data is there and carries on



PLease help
Andrew299
 
How is the information about the file selection passed back from the .exe to the VBA code? Do you have control over the C coding?

Rob
[flowerface]
 
Unfortunately not. the exe file outputs a text file containing simply a file name of an excel file. My VBA program opens this xls file and does wonderful things to it.

Andrew299
 
Could you delete the text file (if it exists) before calling the C program, and then after the shell command loop until the text file is there? Maybe check once every second, to prevent overloading the file system.
Rob
[flowerface]
 
The text file can be deleted before the C program is run as it will contain old information which will be overwritten anyway, but how could I then check that the file is there?
If i call the file I will get errors.

Very good work around thanks
 
Function CheckExistence(filename As String) As Boolean
If Dir(filename) = "" Then
CheckExistence = False
Else
CheckExistence = True
End If
End Function

I have found this code in an older posting I assume it works
I can put in a loop with a wait for x seconds in it to reduce processor time
Trouble is I cant delete the file.
form the help files i get

object.DeleteFile filespec[, force]

as the command I use subbing in my parameters.

However I cant work out the syntax I have tried lots of ways

can anyone help

Thanks
Andrew 299
 
Tek-tips started timing out on me, so excuse the late response. Thiw works:

shell ....
On Error Resume Next
Do
Application.Wait Now() + 1 / 3600 / 24
Err.Clear
Open "c:\hello.txt" For Input As #1
Loop Until Err = 0
On Error GoTo 0
input#1, strMyFileName
close#1


Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top