这似乎对我来说是个窍门。 其中一些我从这样的网站拼凑在一起,其余的都是从头开始创建的。
当我点击我的按钮:显示
- 一个输入框,这是将在电子表格中查找的数值。
- 它看起来在范围内(在代码中指定),对于匹配
- 返回值,它的左边有两列。
- 当它找到匹配时,它将它放入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