Close Dialog Box Via Vba

  • Hello All


    Using VBA, I want to open an htm file via a Word document, edit the HTML script, save the changes then close it.


    I've tried all of the available file converters and number 3 ("Recover Text from Any File") is the only one capable of opening the htm file as text, but it always yields the dialog box "Show Repairs"


    I have tried 4 different methods of automatically closing this dialog box - none of them work


    1) Turn off all alerts, run script, turn on alerts


    Code
    Application.DisplayAlerts= False
    'my script'
    Application.DisplayAlerts=True


    2) Key ALT+F4 to close the active window immediately after opening file


    Code
    SendKeys "%{F4}"


    3) Key TAB 3 times then key ENTER to close the active window immediately after opening file


    Code
    SendKeys "{TAB 3}"
    SendKeys "{ENTER}"


    4) Close the active window immediately after opening file


    Code
    ActiveWindow.Close


    I've looked at

    Code
    Dialogs(wdDialogShowRepairs)

    but you cannot declare "close" or "hide" with it.


    Here is my script in full. It works perfectly if a human is around to close the dialog box...


  • Re: Close Dialog Box Via Vba


    Solved myself. You don't need to use a file converter - just declare format 4


    Code
    ChangeFileOpenDirectory _
        "\\server\folder\"
        Documents.Open FileName:="file.htm", ConfirmConversions:=False, ReadOnly:= _
        False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
        "", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
        Format:=4

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!