マークが述べたことに基づいて、これが試行済みのテスト済みバージョンです。
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 = "ABC@ABC.COM"
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
ファローアップ
情報をありがとう。パラメータ文字列全体が 250 文字に制限されており、メッセージには約 2000 文字が必要であるため、ShellExecute は既に除外していました。しかし、私の場合、実際に機能する唯一のオプションは SE のようです。– Humanoid1000 7時間前
これは、コメントで以下に述べた「恐ろしい(JFCの言う方法が大好きです!!!)」方法で、美しく機能します:)ところで、デフォルトのクライアントとしてOutlookしか持っていないので、それでテストしました。
コード
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 = "ABC@ABC.COM"
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
スナップショット
メッセージを含むテキストファイル
送信直前のメール