我对Outlook表单有点新,但不是整体VBA - 也不是表单的HTML / Web设计。但是,我的问题是找到一种方法将两者结合起来。
我正在设计一个供用户填写的表单,并根据他们在下拉框中填写的内容,它会告诉他们我们希望他们在电子邮件中附加的内容。目前我们已经在Excel中完成了这项工作,基于dropbox,然后VLOOKUPS到包含所需表单的第二个电子表格。
无论如何,我可以在我的VBA Outlook窗体中使用VLOOKUP在Excel中引入Excel,以便它可以查找我们希望用户做什么附件吗?否则,它将是VBA = /
中的SELECT CASE语句的TON答案 0 :(得分:2)
这似乎对我有用。 其中一些我从这样的网站拼凑而成,其余的都是我自己从头开始创建的。
当我点击我的按钮时:
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