简体   繁体   English

在Outlook VBA中打开Excel工作簿时出现不匹配错误

[英]Mismatch error opening excel workbook in outlook vba

I have researched this and not finding anything. 我已经对此进行了研究,但没有发现任何东西。 Shouldn't be that difficult to solve. 应该没有那么难解决。 I am trying to open an Excel workbook with VBA in Outlook but it is throwing a mismatch error and I don't know how to fix. 我正在尝试在Outlook中使用VBA打开Excel工作簿,但它引发了不匹配错误,并且我不知道如何解决。

Function openWorkbook()

Dim xlApp As Object
Dim sourceWB As Excel.Application

Set sourceWB = Workbooks.Open("Z:\Stress Test\GSST Daily\weekly report\June\GSST Daily Estimation week of 06.22.xlsx")

End Function

You need to fix your variable declarations. 您需要修复变量声明。 Since you're using early binding, this is pretty straightforward. 由于您使用的是早期绑定,因此非常简单。 Also I'd change this to a Sub if you're not planning to return anything. 如果您不打算返回任何东西,我也将其更改为Sub

Sub OpenWorkbook()
    Dim xlApp As Excel.Application
    Dim sourceWb As Excel.Workbook

    Set xlApp = New Excel.Application
    Set sourceWb = xlApp.Workbooks.Open("Z:\Stress Test\GSST Daily\weekly report\June\GSST Daily Estimation week of 06.22.xlsx")
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM