Hello all,
I have a managed to find and modify some VBA that will locate as "Save As" window and then paste a file location inside it. My challenge, is that once time expires, a message box pops up prompting a stop or retry. What I am trying to do is instead of a message box, change a few things on my userform, then exit the loop, this would then allow the user to choose to retry or go to a different task via various command buttons. My code to exit this part is flawed, and seems to run without end.
Here is the function code with the message box:
Here is the code as I am trying (unsuccessfully) to modify it:
Any assistance would be greatly appreciated
I have a managed to find and modify some VBA that will locate as "Save As" window and then paste a file location inside it. My challenge, is that once time expires, a message box pops up prompting a stop or retry. What I am trying to do is instead of a message box, change a few things on my userform, then exit the loop, this would then allow the user to choose to retry or go to a different task via various command buttons. My code to exit this part is flawed, and seems to run without end.
Here is the function code with the message box:
VBA Code:
Sub ShowMeTheFile1x()
Const MAX_WAIT_SECS As Long = 25
Const WAIT_SECS As Long = 5
Dim hWnd As Long
Dim ans As VbMsgBoxResult
Dim endTime As Single
endTime = Timer + MAX_WAIT_SECS
Sheets("DAILY01").Select
Range("B20").Select
Selection.Copy
Do
hWnd = FindWindow(vbNullString, "Save As")
If hWnd > 0 Then
SetForegroundWindow hWnd
Application.SendKeys ("^v")
Application.SendKeys ("~")
Exit Do
End If
If Timer > endTime Then
Exit Do
ans = MsgBox("Window not found, try again?", vbQuestion + vbYesNo)
If ans = vbYes Then
endTime = Timer + MAX_WAIT_SECS
Else
Exit Do
End If
Else
PauseMacro WAIT_SECS
End If
Loop
End Sub
VBA Code:
Sub ShowMeTheFile1x()
Const MAX_WAIT_SECS As Long = 25
Const WAIT_SECS As Long = 5
Dim hWnd As Long
Dim ans As VbMsgBoxResult
Dim endTime As Single
endTime = Timer + MAX_WAIT_SECS
Sheets("DAILY01").Select
Range("B20").Select
Selection.Copy
Do
hWnd = FindWindow(vbNullString, "Save As")
If hWnd > 0 Then
SetForegroundWindow hWnd
Application.SendKeys ("^v")
Application.SendKeys ("~")
Exit Do
End If
If Timer > endTime Then
Exit Do
ans = MsgBox("Window not found, try again?", vbQuestion + vbYesNo)
If ans = vbYes Then
endTime = Timer + MAX_WAIT_SECS
Else
Exit Do
End If
Else
PauseMacro WAIT_SECS
End If
Loop
End Sub