Hello all,
I have a macro that looks for a "Save As" window to popup. Once the window pops up, the copied value of the cell will be pasted and then saved. My issue, is that I am now having to run the report program that creates the save as window in a Virtual Machine. as such, my code doesn't seem to notice when the save as box pops up anymore. Does anybody have any advice on how to make my macro look inside my VM?
Here's the code I am using below:
I have a macro that looks for a "Save As" window to popup. Once the window pops up, the copied value of the cell will be pasted and then saved. My issue, is that I am now having to run the report program that creates the save as window in a Virtual Machine. as such, my code doesn't seem to notice when the save as box pops up anymore. Does anybody have any advice on how to make my macro look inside my VM?
Here's the code I am using below:
VBA Code:
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Sub try_saveAs()
Const MAX_WAIT_SECS As Long = 10800 '3 hrs = 10800
Const WAIT_SECS As Long = 5
Dim hWnd As Long
Dim ans As VbMsgBoxResult
Dim endTime As Single
endTime = Timer + MAX_WAIT_SECS
Sheets("DAILY02").Select
Range("D24").Select
Selection.Copy
Do
hWnd = FindWindow(vbNullString, "Save As")
If hWnd > 0 Then
SetForegroundWindow hWnd
'hWnd.WindowState = xlMaximized
Application.SendKeys ("^v")
Application.SendKeys ("~")
Exit Do
End If
If Timer > endTime Then
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