- 帖子
- 132
- 主題
- 31
- 精華
- 0
- 積分
- 167
- 點名
- 0
- 作業系統
- XP
- 軟體版本
- Office 2007
- 閱讀權限
- 20
- 性別
- 男
- 來自
- Taipei
- 註冊時間
- 2011-4-14
- 最後登錄
- 2024-2-28
  
|
Excel VBA寫一個附加檔案到郵件的程式問題
各位前輩:
在這邊又要來請教大家了,小弟我在Excel VBA裡面寫了一個Function的主要功能用來將指定的檔案加入郵件中,之前一直執行的很順利,最近發現,我只要附加的檔案2筆以上,而且有包括一個.msg的outlook郵件檔,加案完成後,該郵件檔打開都是空白,要是只加單筆的郵件檔案則能很正常開啟,我試過了很多次,不管是先加郵件檔,最後才加郵件案,只要是二筆以上除了郵件檔以外的另一種類型檔案,就會發生郵件檔打開會是空白,各位前非能否有好的解決方法呢,我po出我的程式,請大家幫我看看是不是我寫的有什麼問題,感恩。
Function Add_Attachments_File(My_MailItem As Outlook.MailItem, Add_File_Path As String, Add_File_Name As String) As Boolean
Dim My_Attachments As Outlook.Attachments
Dim My_FileSystem As Object
Dim File_State As Boolean
Dim File_Path As String
Dim File_Name As String
Dim File_FullName As String
File_Path = Add_File_Path
File_Name = Add_File_Name
Correct_Path_Name File_Path, File_Name, File_FullName
'上列副程式,只是將代入的路徑與檔名作一個整理,並合併出完整路徑
Set My_FileSystem = CreateObject("Scripting.FileSystemObject")
Set My_Attachments = My_MailItem.Attachments
File_State = Check_Appoint_File(File_Path, File_Name, True)
'上列是只單純檢驗該檔案是否有真實存在
If File_State Then
If StrComp(My_FileSystem.GetExtensionName(File_FullName), "msg", vbTextCompare) = 0 Then
'目前我們只有Outlook的檔案要特別設定OlAttachmentType為olEmbeddeditem
My_Attachments.Add File_FullName, olEmbeddeditem
Else
'其它檔案格式都設定OlAttachmentType為olByValue
My_Attachments.Add File_FullName, olByValue
End If
Add_Attachments_File = True
Else
Add_Attachments_File = False
End If
Exit_Function:
Set My_Attachments = Nothing
Set My_FileSystem = Nothing
End Function |
|