having excel delay....

Davers

Well-known Member
Joined
Sep 17, 2002
Messages
1,165
I'm having Excel automatically open an application, and then use the SendKeys Method to run a query in the program, and have the query export a document to my desktop, the problem is, the query takes anywhere from 10 seconds, to 10 minutes to run, depending on several factors. Is there a way other than using the Wait Method and specifying a specific length of time, to have Excel wait until the query is finished running and exporting before it goes on to the next part of the code, or key strokes? Here is the pertinent part of the code below....

'Export
SendKeys "%{f}", True
SendKeys "{e 2}", True
SendKeys "~", True
SendKeys "{TAB 8}", True
SendKeys "C:\WINDOWS\Desktop\TRACOutput.xls", True
SendKeys "~ 2", True
KillProcess
End Sub

The KillProcess shuts the program down. It unfortunately shuts the program down immediately. I've tried using SendKeys to use the File Menu to Exit the program, but that runs immediately too....any ideas??

Thanks,

Dave M.
 
:cry: Unfortunately the file is created right away...so the application closes down....the file is then blank.... :( Any other ideas?

How about if it tries to open the file...if it's not done exporting data to it, or it's still in use by the system...isn't it possible to put something in the code based on that?

I'm grasping at straws here.... :oops: :cry:

Thanks for all the help!!

Dave M.
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Sorry about this...or, I think it's possible to check the size of a file? How about if it keeps checking the size of the file, and if it stays the same size after several seconds then quit the app?

:roll:

Dave M.
 
Upvote 0
You can get the current file size with

FileLen(PathName)

I guess you could store in a variable the file size "before" the current check, and compare it with the current one, if its the same, the file has been finished creating ??
 
Upvote 0
This may or may not work. Depends on the locking used by the application which is writing to the file. I am unsure about using the file length because I doubt that the buffer will be written to the disk in a timely manner. The code below will attempt to lock the file from other applications. An error should occur if another application is already accessing it. When no error is found, it will be assumed that the query is finished.


Code:
Dim lngCounter As Long
Dim intFileHwnd As Integer

Do While lngCounter < 6000
    lngCounter = lngCounter + 1
    Sleep 100 'wait for 1/10th second
    If lngCounter Mod 10 = 0 Then
        intFileHwnd = FreeFile
        On Error Resume Next
        Open FullNameAndPath For Append Lock Read Write As #intFileHwnd
        Close #intFileHwnd
        If Err.Number = 0 Then Exit Do
    End If
    DoEvents 'yield processes
Loop

Tom
 
Upvote 0
THANK YOU VERY MUCH!!!!! Works like a charm!!! No one will know how I get all my work done so fast in the mornings!!! :D

Thanks again!

Dave M.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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