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
2) Key ALT+F4 to close the active window immediately after opening file
3) Key TAB 3 times then key ENTER to close the active window immediately after opening file
4) Close the active window immediately after opening file
I've looked at
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...
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