[英]Pull data from excel file on SharePoint 2016 using vba?
[英]Excel 2016: open and close an Excel file programmatically from sharepoint
我有此测试代码,尝试启动一个隐藏的Excel进程,从某个位置加载一个Excel文件(“ fileToOpen”),对该文件执行某些操作,然后关闭该文件,最后关闭Excel进程。 我正在Excel 2016中执行测试。
Sub test()
Dim excelapp As Object
Dim wbk As Workbook
Set excelapp = CreateObject("excel.Application")
excelapp.Visible = True
On Error GoTo error_handler
Set wbk = excelapp.Workbooks.Open(filename:=fileToOpen, ReadOnly:=True)
' Do something
wbk.Close SaveChanges:=False
excelapp.Quit
Set excelapp = Nothing
Exit Sub
error_handler:
MsgBox "A problem occurred", vbOKOnly, "Error"
excelapp.Quit
Set excelapp = Nothing
End Sub
出于某种原因,从SharePoint加载文件后,Excel进程在excelapp.Quit
之后excelapp.Quit
,但是从本地驱动器加载文件后,Excel进程将被excelapp.Quit
。 这在Excel 2010中也可以正常工作,即Excel进程已正确终止。
感谢您提供有关阅读后如何正确关闭文件的帮助。
尝试更改
wbk.Close SaveChanges:=False
excelapp.Quit
Set excelapp = Nothing
对此
wbk.Close SaveChanges:=False
Application.Quit
Application.DisplayAlerts = False
Set excelapp = Nothing
和
error_handler:
MsgBox "A problem occurred", vbOKOnly, "Error"
excelapp.Quit
Set excelapp = Nothing
对此
error_handler:
MsgBox "A problem occurred", vbOKOnly, "Error"
Application.Quit
Application.DisplayAlerts = False
Set excelapp = Nothing
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.