簡體   English   中英

VBA Outlook可通過用戶表單實現卓越表現

[英]VBA Outlook to excel via userform

我在將宏從Outlook用戶窗體轉換為Excel時遇到了一些麻煩。 由於某些原因,評估部分沒有給出正確的答案,有什么想法嗎?

 Private Sub btnOK_Click() Dim ctrtype As String Dim client As String Dim terminal As String Dim ctr As String Dim week As String Dim vMatch As Variant Dim sformula As String Dim xlApp As Object, xlBook As Object ctrtype = ComboBox1.Value client = ComboBox2.Value ctr = TextBox1.Value terminal = ComboBox3.Value week = ComboBox4.Value Set xlApp = GetObject(, "Excel.Application") If xlApp Is Nothing Then Set xlApp = CreateObject("Excel.Application") End If Set xlBook = xlApp.Workbooks.Open("C:\\Users\\kkovask\\Desktop\\RsA2015.xlsx") xlBook.Sheets(client).Activate sformula = "MATCH(1,(A:A=" & week & ")*(B:B=" & ctrtype & ")*(C:C=""""),0)" vMatch = Evaluate(sformula) If IsNumeric(vMatch) Then MsgBox Range("C" & vMatch).Address Else: MsgBox "Customer has reached their limit" xlBook.Close SaveChanges:=True Set xlBook = Nothing Set xlApp = Nothing End Sub 

不用看實際公式:

 vMatch = xlBook.Sheets(client).Evaluate(sformula)

您需要讓Excel運行Evaluate ,但是您應該使用Worksheet表單而不是Application表單,否則,可能會在與您正在使用的工作表不同的工作表的上下文中評估公式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM