2013-05-13 146 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