2016-05-30 14 views
0

添付ファイルをスクリプトにドロップするだけで送信できます。ドラッグアンドドロップからファイルパスと拡張子を取得するには? BVS

私は、ファイルを送信し、このいずれかを(それは私の作品)見つけた:私は必要なもの

Set fso=CreateObject("Scripting.FileSystemObject") 
strSMTP="smtp.gmail.com" 
strSubject="[email protected]" 
strSubject2="Attachment file" 
strBody="-" 
strAttach="FILEPATH" 
If fso.FileExists(strAttach) then 
Set iMsg = CreateObject("CDO.Message") 
Set iConf = CreateObject("CDO.Configuration") 
iConf.Load -1 ' CDO Source Defaults 
Set Flds = iConf.Fields 
With Flds 
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTP 
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]" 
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password" 
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1 
.Update 
End With 
With iMsg 
Set .Configuration = iConf 
.To = "[email protected]" 
.CC = "" 
.BCC = "" 
.From = "[email protected]" 
.Subject = strAttach 
.TextBody = strBody 
.AddAttachment strAttach 
.Send 
End With 
Set iMsg = Nothing 
Set iConf = Nothing 
Else 
MsgBox "The specified attachment does not exist" 
End if 

は私がパスを持つ第六行strAttach="FILEPATH"を変更することができます。このスクリプトに変更され、メールをドロップしたファイルの拡張子を入力し、「メールスクリプトを送信」を実行します。

私の質問に関連するこの2つのリンクが見つかりましたが、私はそれらを使用する方法がわかりません、これらもあなたを助けることを願っています。 How to get the fully qualified path for a file in VBScript? http://vba-tutorial.com/parsing-a-file-string-into-path-filename-and-extension/

最初のものは、単にファイルパスと新しいウィンドウの拡張を示していますが、私はそれが第6行に上書きする必要があります。 誰かが私を助けることができますか?私はプログラマーではなく、後で別のコンピュータで印刷する必要があるため、自分のメールにファイルを送信できるようにしたいと考えています。

私の英語のために残念です。私はネイティブスピーカーではありません。前もって感謝します!

答えて

0

使用Arguments Property (WScript Object)

ArgumentsプロパティがWshArgumentsオブジェクト(引数の コレクション)が含まれています。 0から始まるインデックスを使用して、このコレクションの個別の引数を 取得します。

Set fso=CreateObject("Scripting.FileSystemObject") 
strSMTP="smtp.gmail.com" 
strSubject="[email protected]" 
strSubject2="Attachment file" 
strBody="-" 

''''''''''''''''''''''''''''''''''' strAttach="FILEPATH" 
Set objArgs = WScript.Arguments 
For ii = 0 to objArgs.Count - 1 
    SendMyMail fso.GetAbsolutePathName(CStr(objArgs(ii))) 
Next 

Sub SendMyMail(ByVal strAttach) 
    If fso.FileExists(strAttach) then 
     Set iMsg = CreateObject("CDO.Message") 
     Set iConf = CreateObject("CDO.Configuration") 
     iConf.Load -1 ' CDO Source Defaults 
     Set Flds = iConf.Fields 
     With Flds 
     .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
     .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTP 
     .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 
     .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 
     .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]" 
     .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password" 
     .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1 
     .Update 
     End With 
     With iMsg 
     Set .Configuration = iConf 
     .To = "[email protected]" 
     .CC = "" 
     .BCC = "" 
     .From = "[email protected]" 
     .Subject = strAttach 
     .TextBody = strBody 
     .AddAttachment strAttach 
     .Send 
     End With 
     Set iMsg = Nothing 
     Set iConf = Nothing 
    Else 
     MsgBox strAttach & vbCrLf & "The specified attachment does not exist" 
    End if 
End Sub 

shell:sendto参照:Customize the Send To Menu in Windows 10, 8, 7, or Vista)をファイル(複数可)を右クリックし、メニューからSendTo…を使用してドラッグ&ドロップなど

  • を使用して

    • を動作するはずです。

    コードを簡略化するため、Paul Sadowskiの記事Sending email with CDOを確認してください。

  • +0

    ありがとうございました。私もその記事をチェックします。良い一日を。 –

    関連する問題