I need to use the "Save As" dialog box to save a file on the Desktop. (Windows XP) To do that I made this code to change value of the combobox on the top combobox to "desktop". When I run it, the text changes to desktop, but the change event doesn't fire, which means it will still save in the default folder. If I click on the combobox and away maually after running this code that fires the event and the destination folder actually changes, but I can't do this with code. I don't want to use sendkeys and simulated mouse clicks as they are not so reliable. If I could simulate typing "Desktop" in the combobox that could also work, but I didn't manage to that either.
Please help it took me really long time to get this far. :(
P.S: There's no easier way. This is part of an exporting process of non-microsoft application which uses the "Save As" dialog box.
Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Const CB_FINDSTRINGEXACT = &H158
Const CB_SETCURSEL = &H14E
Sub test()
Dim hwnd As Long, cbox As Long, itemid As Long
hwnd = FindWindow("#32770", "Save as")
cbox = FindWindowEx(hwnd, 0&, "combobox", vbNullString)
itemid = SendMessage(cbox, CB_FINDSTRINGEXACT, 0, "Desktop")
SendMessage cbox, CB_SETCURSEL, ByVal itemid, ByVal itemid
End Sub
P.S: There's no easier way. This is part of an exporting process of non-microsoft application which uses the "Save As" dialog box.