下面的代码在 Windows 7 中运行良好。我在 Windows XP 中收到错误“ ActiveX 组件无法创建对象:'Word.Application' ”。XP中没有安装Microsoft Word,这是错误的原因吗?我是 vbscript 的新手。解决方案是什么?
Const msoFileDialogOpen = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set objWord = CreateObject("Word.Application")
Set WshShell = CreateObject("WScript.Shell")
strInitialPath = WshShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Desktop\"
objWord.ChangeFileOpenDirectory(strInitialPath)
With objWord.FileDialog(msoFileDialogOpen)
.Title = "Select the file to process"
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "All Files", "*.*"
.Filters.Add "Excel Files", "*.xls;*.xlsx"
.Filters.Add "Text Files", "*.txt"
.Filters.Add "Various Files", "*.xls;*.doc;*.vbs"
If .Show = -1 Then 'short form
For Each File in .SelectedItems 'short form
Set objFile = fso.GetFile(File)
WScript.Echo objFile.Path
Next
Else
End If
End With
'Close Word
objWord.Quit