2013-05-13 144 views
0

我對Outlook表單有點新,但對於VBA整體來說並不是 - 也不是HTML/Web設計的表單。但是,我的問題是找到一種方法來結合這兩者。Outlook窗體:從Excel導入/ VLOOKUP數據?

我想設計一個表格供用戶填寫,並根據他們在下拉框中填寫的內容,它會告訴他們我們希望他們在電子郵件中附加的內容。目前我們已經在Excel中完成了這一工作,基於Dropbox的VLOOKUPS到包含所需表單的第二張電子表格。

無論如何,我可以在我的VBA Outlook窗體中使用VLOOKUP在幕後引入Excel,以便它可以查找我們希望用戶執行哪些附件?否則,它將是VBA中的SELECT CASE語句的TON =/

+0

對不起 - 不理解你的字典引用(或笑話?)鏈接。可能解釋更多?如果有什麼最接近的,我可以找到這個:http://stackoverflow.com/questions/3196081/building-forms-for-outlook-2007 - 但在這個問題,他們正在將Excel轉換爲Access數據庫表。坦率地說,我不明白爲什麼Excel表格不能做到這一點。 – user2296381 2013-05-13 13:41:27

+0

任何人都可以提供幫助的機會?除非有人知道從Outlook表單模板中提取Excel數據的方式 - 因爲試圖從Excel中編寫我需要的所有數據只會太困難。 – user2296381 2013-05-14 13:55:10

回答

2

這似乎對我來說是個竅門。 其中一些我從這樣的網站拼湊在一起,其餘的都是從頭開始創建的。

當我點擊我的按鈕:顯示

  • 一個輸入框,這是將在電子表格中查找的數值。
  • 它看起來在範圍內(在代碼中指定),對於匹配
  • 返回值,它的左邊有兩列。
  • 當它找到匹配時,它將它放入Outlook中的主題行中。
Dim jobno As String 
Dim Proj As String 

Sub Test() 
    jobno = InputBox("Job Number?", "Test") 
    GetNameFromXL 
    If jobno <> "" Then 
     Set myItem = Application.CreateItem(0) 
     If Proj <> "" Then 
      myItem.Subject = jobno & " - " & Proj & " - " & Format(Date, "dd.mm.yy") 
     Else 
      myItem.Subject = jobno & " - " & Format(Date, "dd.mm.yy") 
     End If 
     myItem.Display 
    Else 
     Exit Sub 
    End If 
End Sub 


Sub GetNameFromXL() 

'Late binding. No reference to Excel Object required. 
Dim xlApp As Object 
Dim xlWB As Object 
Dim xlWS As Object 

Set xlApp = CreateObject("Excel.Application") 
'Open the spreadsheet to get data 
Set xlWB = xlApp.Workbooks.Open("X:\...\FILENAME.xlsx") ' <-- Put your file path and name here 
Set xlWS = xlWB.Worksheets(1) ' <-- Looks in the 1st Worksheet 

Debug.Print "-----Start of 'For Each' loop" 
For Each c In xlWS.Range("A6:A100") 'Change range to value you want to 'VLookUp' 
Proj = c.Offset(0, 2).Value 'This looks at the 2nd column after the range above 
Debug.Print c & Proj 
    If jobno = c Then 
     Debug.Print "-----Match Found: " & jobno & " = " & Proj 
     GoTo lbl_Exit 
    Else 
    End If 
Next c 
Debug.Print "-----End of For Each loop" 
MsgBox jobno & " not found in WorkBook." 

'Clean up 
Set xlWS = Nothing 
Set xlWB = Nothing 
Set c = Nothing 
Proj = "" 
xlApp.Quit 
Set xlApp = Nothing 
lbl_Exit: 
Exit Sub 
End Sub