![](/img/trans.png)
[英]How to fix Compile Error: User-defined type not defined when using Excel VBA from Outlook?
[英]User defined type not defined when creating Outlook Object
Dim oApp As Outlook.Application
Dim oMail As MailItem
Dim oMail As String
Dim strbody As String
Dim fdatum As String
Dim VorschauBereich As Range
Dim Tabnr As Integer
Dim Tabtext As String
Set oApp = CreateObject("Outlook.application")
Set oMail = oApp.CreateItem(oIMailItem)
我得到標題中命名的錯誤,光標跳轉到 Dim Dim oApp As Outlook.Application
要解決此問題,您可以通過在參考中添加 Mircrosoft 對象庫來使用早期綁定(從工具菜單中)。 或者,您可以通過將 Outlook 對象聲明更改為以下內容來使用后期綁定:
Dim oApp As Object
Dim oMail As Object
然后像這樣創建對象:
Set oApp = CreateObject("Outlook.application")
Set oMail = oApp.CreateItem(0)
根據您的excel WB是否被其他人使用,我更喜歡后期綁定以避免其他人機器上的引用出現任何問題。 后期綁定的缺點是您在編碼時無法獲得 inteli-text 幫助。 希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.