通过VB脚本打开excel时出现800A03EC错误

时间:2018-11-09 12:16:33

标签: excel vbscript

我最近开始使用vb脚本,并编译了一个vb脚本(当然是谷歌搜索)以打开excel工作表。但是我收到800A03EC错误-对不起,我们找不到Excel工作表。是重命名/移动还是删除?

enter image description here

我可以手动打开文件,没有任何错误。

这是因为文档分类吗?

这是我的代码

Option Explicit

Sub FileSplit()

Dim Workbook
Dim Worksheet
Dim fileName
Dim filePath
Dim objExcel
Dim objWorkbook
Dim rowCount
'Application.ScreenUpdating = False
'Application.Calculation = xlCalculationManual
MsgBox ("Hello World")
filePath = locateFile() 


If filePath = "" Then 
   MsgBox "Operation canceled", vbcritical 
Else 
   wscript.echo filePath
   fileName = Mid(filePath, InStrRev(filePath, "\") + 1)
   wscript.echo fileName
End If 

Set objExcel = CreateObject("Excel.Application")  

objExcel.Visible = True  

Set objWorkbook = objExcel.Workbooks.Open(fileName) 
Set objWorkbook = Activeworkbook 

End Sub


Function locateFile() 
    locateFile = CreateObject("WScript.Shell").Exec( _ 
    "mshta.exe ""about:<input type=file id=f>" & _ 
    "<script>resizeTo(0,0);f.click();new ActiveXObject  ('Scripting.FileSystemObject')" & _ 
 ".GetStandardStream(1).WriteLine(f.value);close();</script>""" _ 
      ).StdOut.ReadLine() 


End Function


call FileSplit

非常感谢。

0 个答案:

没有答案