1

After VBA clicks save as, and the window appears, I'd like to be able to set the file path. I've tried ChDir() and direct downloads with winhttp, but neither work for this. My source for the code is at: https://www.mrexcel.com/forum/excel-questions/502298-need-help-regarding-ie-automation-using-vba-3.html

Any help figuring out how to set the file path, I'm assuming in the top window (path window) of the file explorer, would be helpful.

***THIS IS NOT A DUPLICATE QUESTION. WINHTTP DOWNLOAD WILL NOT WORK ON THIS WEBSITE.

Below is what I'm currently trying, but does not change the file path in the file explorer window, but only adds the file path in the File name window, which doesn't change where the file is saved.

Private Sub Save_As_Set_Filename(ByRef ZipfileName)
    Dim hwnd As Long
    Dim timeout As Date
    Dim fullFilename As String

    'Find the Save As window, waiting a maximum of 10 seconds for it to appear
    timeout = Now + TimeValue("00:00:10")
    Do
        hwnd = FindWindow("#32770", "Save As")
        DoEvents
        Sleep 300
    Loop Until hwnd Or Now > timeout

    If hwnd Then
        SetForegroundWindow hwnd
        'Find the child DUIViewWndClassName window
       hwnd = FindWindowEx(hwnd, 0, "DUIViewWndClassName", vbNullString)
    End If

    If hwnd Then
        SetForegroundWindow hwnd
        'Find the child DirectUIHWND window
        hwnd = FindWindowEx(hwnd, 0, "DirectUIHWND", "")
    End If

    If hwnd Then
        'Find the child FloatNotifySink window
        hwnd = FindWindowEx(hwnd, 0, "FloatNotifySink", "")
    End If

    If hwnd Then
        'Find the child ComboBox window
        hwnd = FindWindowEx(hwnd, 0, "ComboBox", "")
    End If

    If hwnd Then
        'Find the child Edit window
        hwnd = FindWindowEx(hwnd, 0, "Edit", "")
    End If

    If hwnd Then
        ZipfileName = Get_Window_Text(hwnd)

        'If specified, ensure folder ends with \
        folder = Environ("USERPROFILE") & "\Downloads\"
        If folder <> "" And Right(folder, 1) <> "\" Then folder = folder & "\"
        fullFilename = folder & ZipfileName 

        'Populate the Edit window with the full file name
        Sleep 300
        SetForegroundWindow hwnd
        SendMessageByString hwnd, WM_SETTEXT, Len(fullFilename ), fullFilename 
    End If

End Sub
W-hit
  • 353
  • 3
  • 14

0 Answers0