Announcement

Collapse
No announcement yet.

Close Dialog Box Via Vba

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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...

    Code:
    Sub Update_File()
        
        ChangeFileOpenDirectory _
        "\\server\folder\"
        Documents.Open FileName:="file.htm", ConfirmConversions:=False, _
            ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
            PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
            WritePasswordTemplate:="", Format:=FileConverters(3).OpenFormat, _
            Encoding:=1252 _
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "BODY BGCOLOR=#003399"
            .Replacement.Text = "BODY BGCOLOR=#FFFFFF"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
        ActiveDocument.Save
        ActiveDocument.Close
    End Sub

  • #2
    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

    Comment


    • #3
      Re: Close Dialog Box Via Vba

      Hey thanks for sharing your solution.
      Reafidy

      Forum Rules | Anatomy Of A Good Thread Title | What Have You Tried So Far? | Are You A Cross Poster?

      Comment

      Working...
      X