Xây dựng dựa trên những gì Marc đã đề cập, Dưới đây là đã thử và thử nghiệm phiên bản.
Option Explicit
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Sub SendMail()
Dim objMail As String
Dim oMailSubj, oMailTo, oMailBody As String
On Error GoTo Whoa
oMailSubj = "YOUR SUBJECT GOES HERE"
oMailTo = "[email protected]"
oMailBody = "BLAH BLAH!!!!"
objMail = "mailto:" & oMailTo & "?subject=" & oMailSubj & "&body=" & oMailBody
ShellExecute 0, vbNullString, objMail, vbNullString, vbNullString, vbNormalFocus
Application.Wait (Now + TimeValue("0:00:03"))
Application.SendKeys "%s"
Exit Sub
Whoa:
MsgBox Err.Description
End Sub
followup
Cảm ơn thông tin. Tôi đã loại trừ ShellExecute vì nó giới hạn toàn bộ chuỗi tham số đến 250 char và tôi cần khoảng 2000 cho thông báo. Nhưng có vẻ như SE là lựa chọn duy nhất sẽ thực sự hoạt động trong trường hợp của tôi. - Humanoid1000 7 giờ trước
Đây là "Horrible (Tôi thích cách JFC nói rằng !!!)" Con đường tôi đề cập dưới đây trong các ý kiến mà tác phẩm đẹp mắt :) BTW Tôi có chỉ Outlook là ứng dụng khách mặc định của tôi vì vậy tôi đã thử nghiệm nó với điều đó.
MÃ
Option Explicit
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub SendMail()
Dim objMail As String
Dim oMailSubj As String, oMailTo As String
Dim i As Long
Dim objDoc As Object, objSel As Object, objOutlook As Object
Dim MyData As String, strData() As String
On Error GoTo Whoa
'~~> Open the txt file which has the body text and read it in one go
Open "C:\Users\Siddharth Rout\Desktop\Sample.Txt" For Binary As #1
MyData = Space$(LOF(1))
Get #1, , MyData
Close #1
strData() = Split(MyData, vbCrLf)
Sleep 300
oMailSubj = "YOUR SUBJECT GOES HERE"
oMailTo = "[email protected]"
objMail = "mailto:" & oMailTo & "?subject=" & oMailSubj
ShellExecute 0, vbNullString, objMail, vbNullString, vbNullString, vbNormalFocus
Sleep 300
Set objOutlook = GetObject(, "Outlook.Application")
'~~> Get a Word.Selection from the open Outlook item
Set objDoc = objOutlook.ActiveInspector.WordEditor
Set objSel = objDoc.Windows(1).Selection
objDoc.Activate
Sleep 300
For i = LBound(strData) To UBound(strData)
objSel.TypeText strData(i)
objSel.TypeText vbNewLine
Next i
Set objDoc = Nothing
Set objSel = Nothing
'~~> Uncomment the below to actually send the email
'Application.Wait (Now + TimeValue("0:00:03"))
'Application.SendKeys "%s"
Exit Sub
Whoa:
MsgBox Err.Description
End Sub
SNAPSHOT
Text File trong đó có thông điệp
![enter image description here](https://i.stack.imgur.com/AcJMg.png)
Email ngay trước khi nó được gửi
![enter image description here](https://i.stack.imgur.com/9PKz1.png)
'Bỏ qua câu trả lời của tôi.' + 1 :-) Bạn đang đi đúng hướng. –
@SiddharthRout, đã được nhìn thấy rất nhiều bạn về những câu hỏi Excel gần đây Siddarth. Làm tốt lắm! – Marc
Luôn luôn yêu một câu hỏi hay;) –