VBS Error when saving a Word file
VBS script. I'm trying to save a Word file from doc format to docx format.
If I do not specify the extension of the saved file, WSH returns the error "Invalid file name" 800A1420. If you specify the docx extension, then "The file type and extension are not compatible" 800A18696. I set the second parameter: file type, tried SaveAs2
. The situation has not changed. I understand that I am doing something wrong, but what is not clear.
Option Explicit
Const msoFileDialogOpen = 1
Const wdDoNotSaveChanges = 0
Dim strText
Dim strPath
Dim strFileName
Dim strFileNameMask
strPath = "C:\Documents and Settings\User\Мои документы\"
strFileNameMask = "*.doc"
strFileName = "A1.docx"
With WScript.CreateObject("Word.Application")
.Visible = True
With .FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.InitialFileName = strPath & strFileNameMask
If .Show() = -1 Then
With .Application.Documents.Open(.SelectedItems.Item(1))
strText = .Range.Text
.SaveAs strPath & strFileName
End With
End If
End With
.Quit wdDoNotSaveChanges
End With
WScript.Quit
1
1 answers
You need to call the procedure beforesaving SaveAs. This procedure must specify the format of the saved file. For docx, this parameter is equal to 12
Accordingly, you need to change the save line in the script to the following:
.SaveAs strPath & strFileName , 12
0
Author: Daemon-5, 2019-02-14 09:38:48