這似乎對我來說是個竅門。 其中一些我從這樣的網站拼湊在一起,其餘的都是從頭開始創建的。
當我點擊我的按鈕:顯示
- 一個輸入框,這是將在電子表格中查找的數值。
- 它看起來在範圍內(在代碼中指定),對於匹配
- 返回值,它的左邊有兩列。
- 當它找到匹配時,它將它放入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
對不起 - 不理解你的字典引用(或笑話?)鏈接。可能解釋更多?如果有什麼最接近的,我可以找到這個:http://stackoverflow.com/questions/3196081/building-forms-for-outlook-2007 - 但在這個問題,他們正在將Excel轉換爲Access數據庫表。坦率地說,我不明白爲什麼Excel表格不能做到這一點。 – user2296381 2013-05-13 13:41:27
任何人都可以提供幫助的機會?除非有人知道從Outlook表單模板中提取Excel數據的方式 - 因爲試圖從Excel中編寫我需要的所有數據只會太困難。 – user2296381 2013-05-14 13:55:10