读书人

vista系统vbs调用COM组件打开文件有关

发布时间: 2012-03-02 14:40:28 作者: rapoo

vista系统vbs调用COM组件打开文件问题
set objFile = CreateObject("SAFRCFileDlg.FileOpen")

bRet = objFile.OpenFileOpenDlg

if bRet then
Wscript.Echo "文件打开成功!文件名为:" & objFile.filename
else
wscript.quit
End if
xp下可以使用但是vista系统下需要怎么写才能实现呢!
错误提示

行:1
字符:1
错误:ActiveX 部件不能创建对象: 'SAFRCFileDlg.FileOpen'
代码:800A01AD
源: Microsoft VBScript 运行时错误



[解决办法]
Dim oCDlg
Dim sTmp

Set oCDlg = CreateObject( "MSComDlg.CommonDialog" )
If oCDlg Is Nothing Then
MsgBox "CreateObject( 'MSComDlg.CommonDialog' ) failed."
Exit Sub
End If

oCDlg.MaxFileSize = 10000
' Setting other oCDlg.Properties
' oCDlg.Filter = ...
' ...

oCDlg.ShowOpen

document.all.sleTOSEND.value = oCDlg.Filename ' FSpec
[解决办法]
没办法啊,在win7(没用过vista)里面,SAFRCFileDlg.FileSave和SAFRCFileDlg.FileOpen以及UserAccounts.CommonDialog都不能被正确地创建(不知道是否因为权限的原因,因为在win7中用script不如用c#,所以没有深究),所以,如果要通用XP和win7,可以试试IE里面的input:

VBScript code
Set oIE = CreateObject("InternetExplorer.Application")    oIE.Navigate "About:Blank"    oIE.Document.Write "<HTML><BODY><INPUT TYPE='file' ID='x'/></BODY></HTML>"Set oElement = oIE.Document.getElementById("x")    oElement.Click    WScript.Echo oElement.Value    oIE.Quit 

读书人网 >vbScript

热点推荐