嗨,谢谢你的帮助。
我在Outlook 2010 &2007中有以下代码:
Sub Openexcel()
Dim xlApp As Object
Dim sourceWB As Workbook
Dim sourceSH As Worksheet
Dim strFile As String
Set xlApp = CreateObject("Excel.Application")
With xlApp
.Visible = True
.EnableEvents = False
End With
strFile = "E:\All documents\susan\work\Excel projects\saving files to directory Clean.xls"
Set sourceWB = Workbooks.Open(strFile, , False, , , , , , , True)
Set sourceSH = sourceWB.Worksheets("Sheet2")
sourceWB.Activate
End Sub
此代码在打开outlook后第一次使用它时工作,但如果然后关闭excel文件,则无法再次使用它。我要把这本工作书翻三遍
问题在
Outlook开放excel看到了同样的问题,但我不明白答案。
“我弄清楚了。在打开第二个工作簿之前,我打开了一个不同的工作簿,然后关闭了它,这干扰了它。为了解决这个问题,我一直打开excel应用程序,然后将工作簿对象重置为我想要的新工作簿。”
如果有人能帮忙编写额外的代码,那就太好了。
发布于 2015-03-13 17:11:37
在Excel文件打开后Excel交互不起作用中发现了很好的代码。
为什么上周我找不到这个谁知道呢。
Sub Openexcel()
' change
Dim xlApp As Excel.Application
Dim sourceWB As Excel.Workbook
Dim sourceSH As Excel.Worksheet
'change
Set xlApp = New Excel.Application
With xlApp
.Visible = True
.EnableEvents = False
'.UserControl = False
'.DisplayAlerts = False
'.AskToUpdateLinks = False
End With
strFile = "E:\All documents\susan\work\Excel projects\saving files to directory Clean.xls"
'change
Set sourceWB = xlApp.Workbooks.Open(strFile, , False, , , , , , , True)
Set sourceSH = sourceWB.Worksheets("Sheet2")
sourceWB.Activate
End Sub
谢谢你们的想法。
发布于 2015-03-11 02:16:15
您需要在全局范围内声明Excel应用程序,并使用它打开其他工作簿。不创建用于打开新文件的新Excel实例。您可能会发现如何从Visual中实现Microsoft的自动化的文章很有帮助。
例如,在事件处理程序之外声明Application对象:
Dim oXL As Excel.Application
Private Sub Command1_Click()
Dim oWB As Excel.Workbook
因此,您将能够重用它来关闭和打开新的工作簿。
https://stackoverflow.com/questions/28970516
复制相似问题