I need help on this, i don't know much about windows api, and i'm trying to figure out how i can save a file, and overwrrite it (already exists with the same name).
What i am doing is find the application first, send some keys like alt, some down keys, enter.(file->Save as->Enter)
When i press enter, it comes a new window asking confirmation about saving the file.
And then excel freezes, with out finding Confirm Save As window and pressing "Yes".
It happens in command:
Can anyone help me solving this. Is it happening because it focus is still in save as window or something?
Should i use other way to do what i want?
Thanks for your advice and your time!
What i am doing is find the application first, send some keys like alt, some down keys, enter.(file->Save as->Enter)
When i press enter, it comes a new window asking confirmation about saving the file.
And then excel freezes, with out finding Confirm Save As window and pressing "Yes".
It happens in command:
Call SendMessage(SaveButton, BM_CLICK, 0&, ByVal 0&)
Can anyone help me solving this. Is it happening because it focus is still in save as window or something?
Should i use other way to do what i want?
Code:
Public Declare PtrSafe Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare PtrSafe Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Public Declare PtrSafe Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare PtrSafe Function SendMessageByString Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long
Public Declare PtrSafe Function SetActiveWindow Lib "user32.dll" (ByVal hWnd As Long) As Long
Public Declare PtrSafe Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdSHow As Long) As Long
Public Declare PtrSafe Function BringWindowToTop Lib "user32" (ByVal lngHWnd As Long) As Long
Public Declare PtrSafe Function EnableWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal fEnable As Long) As Long
Public Declare PtrSafe Function GetActiveWindow Lib "user32" () As Long
Public Declare PtrSafe Function GetFocus Lib "user32.dll" () As Long
Public Declare PtrSafe Function SendDlgItemMessage Lib "user32.dll" Alias "SendDlgItemMessageA" (ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const WM_CLOSE As Long = &H10
Public Const SW_SHOW As Integer = 5
Public Const WM_SETTEXT As Long = &HC
Public Const BM_CLICK As Long = &HF5&
Sub PulseAutomation()
CCPUlse = FindWindow(vbNullString, "HxD - [C:\Users\Matthew\Desktop\changelog.txt]")
view13844BringWindowToTop = BringWindowToTop(CCPUlse)
DoEvents
SendKeys "%", True
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True
SendKeys "~", True
Application.Wait (Now + #12:00:01 AM#)
SaveAsWindow = FindWindow(vbNullString, "Save As")
SaveButton = FindWindowEx(SaveAsWindow, 0&, "Button", "&Save")
Call EnableWindow(SaveButton, True)
Call SendMessage(SaveButton, BM_CLICK, 0&, ByVal 0&)
DoEvents
Application.Wait (Now + #12:00:01 AM#)
Dim hWndFind As Long
hWnd = FindWindow(vbNullString, "Confirm Save As")
'get the first child window with the class "Edit" (a textbox to VB)
hWndFind1 = FindWindowEx(hWnd, 0, "DirectUIHWND", vbNullString)
hWndFind2 = FindWindowEx(hWndFind1, 0, "CtrlNotifySink", vbNullString)
hWndFind3 = GetNextWindow(hWndFind2, GW_HWNDNEXT)
hWndFind4 = GetNextWindow(hWndFind3, GW_HWNDNEXT)
hWndFind5 = GetNextWindow(hWndFind4, GW_HWNDNEXT)
hWndFind6 = GetNextWindow(hWndFind5, GW_HWNDNEXT)
hWndFind7 = GetNextWindow(hWndFind6, GW_HWNDNEXT)
hWndFind8 = GetNextWindow(hWndFind7, GW_HWNDNEXT)
hWndFind9 = FindWindowEx(hWndFind8, 0, "Button", vbNullString)
Call SendMessage(hWndFind9, BM_CLICK, 0&, ByVal 0&)
End Sub