程式碼:
Public Declare PtrSafe Function SetTimer Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerfunc As Long) As Long
Public Declare PtrSafe Function KillTimer Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Function WinProcA(ByVal hwnd As Long, ByVal uMsg As Long, _
ByVal idEvent As Long, ByVal SysTime As Long) As Long
KillTimer 0, idEvent
DoEvents
Sleep 100
'使用 Alt + s 鍵來傳送郵件
Application.SendKeys "%s"
End Function
Sub Mail()
Dim objOL As Object
Dim itmNewMail As Object
收件者 = Worksheets("供應商包材").Cells(1, 50)
副本 = Worksheets("供應商包材").Cells(2, 50)
'先存檔
ThisWorkbook.Save
'引用Microsoft Outlook 物件模型
Set objOL = CreateObject("Outlook.Application")
Set itmNewMail = objOL.CreateItem(olMailItem)
With itmNewMail
.Subject = "【每日】" & "CORE架台進銷存_" & DateTime.Date '主旨
.Body = DateTime.Date & " CORE架台進銷存 該檔案會於每日下班前送出" '本文
.To = 收件者 '收件者"
.cc = 副本
'.BCC = "yifan"
'指定附件的路徑
.Attachments.Add ThisWorkbook.FullName
.Display '啟動視窗
SetTimer 0, 0, 0, AddressOf WinProcA
End With
Set objOL = Nothing
Set itmNewMail = Nothing
End Sub
程式碼:
Public Declare PtrSafe Function SetTimer Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerfunc As Long) As Long
Public Declare PtrSafe Function KillTimer Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Function WinProcA(ByVal hwnd As Long, ByVal uMsg As Long, _
ByVal idEvent As Long, ByVal SysTime As Long) As Long
KillTimer 0, idEvent
DoEvents
Sleep 100
'使用 Alt + s 鍵來傳送郵件
Application.SendKeys "%s"
End Function
Sub Mail()
Dim objOL As Object
Dim itmNewMail As Object
收件者 = Worksheets("供應商包材").Cells(1, 50)
副本 = Worksheets("供應商包材").Cells(2, 50)
'先存檔
ThisWorkbook.Save
'引用Microsoft Outlook 物件模型
Set objOL = CreateObject("Outlook.Application")
Set itmNewMail = objOL.CreateItem(olMailItem)
With itmNewMail
.Subject = "【每日】" & "CORE架台進銷存_" & DateTime.Date '主旨
.Body = DateTime.Date & " CORE架台進銷存 該檔案會於每日下班前送出" '本文
.To = 收件者 '收件者"
.cc = 副本
'.BCC = "yifan"
'指定附件的路徑
.Attachments.Add ThisWorkbook.FullName
.Display '啟動視窗
SetTimer 0, 0, 0, AddressOf WinProcA
End With
Set objOL = Nothing
Set itmNewMail = Nothing
End Sub