Hi,
I need to save always a word document also in HTM format beside the normal DOCX.
I have difficulties in interceping all commands the user can use to save/close a document. The Major problem is intercepting the X Close Window application in the right upper corner.
I was trying to use DocumentBeforeSave event:
- class Module EventClassModule:
Public WithEvents appWord As Word.Application
Private Sub appWord_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
If Len(ActiveDocument.path) > 0 Then
MsgBox "I got you", vbOK
SalvaActiveDocumentDocxAndHTM
Cancel = True
Else
Cancel = False
End If
End Sub
Public Sub SalvaActiveDocumentDocxAndHTM()
Dim sNomeFile As String, sPath As String
Dim vTipo As WdViewType
Dim ObjWordDoc As Word.Document, objWordActDoc As Word.Document
Set objWordActDoc = Application.ActiveDocument
With objWordActDoc
.Save
With Application
.ScreenUpdating = False
vTipo = .ActiveWindow.View.Type
End With
sPath = ActiveDocument.path
sNomeFile = sPath + Application.PathSeparator + RemoveExtensionFromFileName(.Name)
.SaveAs2 fileName:=sNomeFile + ".htm", FileFormat:=wdFormatHTML, AddToRecentFiles:=False
'open again file docx
Set ObjWordDoc = Documents.Open(sNomeFile & ".docx")
.Close wdDoNotSaveChanges
With Application
.ActiveWindow.View.Type = vTipo
.ScreenUpdating = True
End With
End With
Set ObjWordDoc = Nothing
Set objWordActDoc = Nothing
End Sub
The problem is avoiding the infinite loop of saving. I tried with a boolean inserted before and after the call of SalvaActiveDocumentDocxAndHtm but without success.
Do you have any suggestions?
Thanks, Lauro