VBA打开工作簿,退出代码 [英] VBA open workbook, exits code
本文介绍了VBA打开工作簿,退出代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用
Private Function readFiles(ByVal lv_path As String, ByRef lx_wrkShDes As Worksheet)
'On Error GoTo ErrorHandling
Dim lx_objectExcel As New Excel.Application
Dim lx_wrkBkSrc As Workbook
Dim lx_wrkShSrc As Worksheet
Dim lx_shrPathObj As Object
Dim lv_shrPath As String
Set lx_shrPathObj = CreateObject("scripting.filesystemobject")
lv_shrPath = Replace(lx_shrPathObj.GetFile(lv_path).ShortPath, mv_longFilePathHelper, "")
Set lx_wrkBkSrc = Workbooks.Open(Filename:=lv_shrPath, ReadOnly:=True)
'Using lx_objectExcel.Workbooks.Open WORKS but not Workbooks.Open
'lx_objectExcel.Workbooks.Open(Filename:=lv_shrPath, ReadOnly:=True)
If Not Library.DoesSheetExist(lx_wrkBkSrc, mv_workSheetName) Then
GoTo ErrorHandling
End If
Set lx_wrkShSrc = lx_wrkBkSrc.Sheets(mv_workSheetName)
'Rest of the function
End Function
它将打开工作簿并立即退出VBA代码.我尝试了 https://support.microsoft.com/en-us/help/555263,但结果相同.
It opens the workbook and exits the VBA code immediately. I tried this https://support.microsoft.com/en-us/help/555263, but same results.
如果我使用新的Excel实例,它不会退出
It does not exit if I use new instance of Excel using
lx_objectExcel.Workbook.open('path')
我不想使用新实例,因为特殊粘贴不适用于新实例,以这种方式打开100册工作簿会浪费很多时间.
I do not want to use a new instance as paste special is not suitable with new instance and opening 100s of Workbooks this way consumes lot of time.
推荐答案
替换:
Workbook.open('path')
使用
Workbooks.Open("PathName")
这篇关于VBA打开工作簿,退出代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文