ActiveDocument.SaveAs2 doesn't work in Excel 2000 but works fine in 2010 and 2016
I used a modified version of the code provided by Jtchase08 in another thread and it works fine in Excel 2010 and 2016 when I change the object library to the corresponding version of Microsoft Word, however in trying to do the same 2000 I get
Runtime error '438': Object does not support this property or method
Debugging takes me here
The complete code I am using is below, if anyone can help modify it to work in 2000, it would greatly appreciate it.
Sub ExportToHTML()
Dim DocPath As String
Dim MsgBoxCompleted
Worksheets("Final Code").Activate
Worksheets("Final Code").Range("A1:A322").Select
Dim AppWord As Object
Set AppWord = CreateObject("Word.Application")
AppWord.Visible = False
Selection.Copy
DocPath = CurDir & Application.PathSeparator & Range("U15")
'Create and save txt file
AppWord.Documents.Add
AppWord.Selection.Paste
AppWord.ActiveDocument.SaveAs2 Filename:=DocPath, FileFormat:=wdFormatText
Application.CutCopyMode = False
AppWord.Quit (wdDoNotSaveChanges)
Set AppWord = Nothing
MsgBoxCompleted = MsgBox("Process complete.", vbOKOnly, "Process complete")
Worksheets("User Input").Activate
End Sub
source to share
I think the best solution would be
If Val(Application.Version) < 14 Then
AppWord.ActiveDocument.SaveAs Filename:=DocPath, FileFormat:=wdFormatText
Else
AppWord.ActiveDocument.SaveAs2 Filename:=DocPath, FileFormat:=wdFormatText
End If
So, for versions before Office 2010, the old feature is usedSaveAs
. And for Office 2010 and newer, there is a new featureSaveAs2
.
Info
The functionSaveAs2
was introduced in Office 2010.
As far as I know, the only difference is that the functionSaveAs2
takes an additional (last) argumentCompatibilityMode
(see WdCompatibilityMode Enumeration).Thus, the old one
SaveAs
can work in newer versions as well, because it is still implemented for compatibility reasons. But we never know if it will be possible to remove it in future versions, so with the solution above, you will get future compatibility if the old oneSaveAs
is removed from VBA.
source to share