2016-05-30 70 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 

我需要的是这个剧本的修改,让我改变了6号线strAttach="FILEPATH"与路径即时消息文件的扩展名,然后执行“发送邮件脚本”。

发现这两个与我的问题有关的链接,但我不知道如何使用它们,希望这些链接也能帮助你。 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/

第一个只是显示的文件路径和新的窗口扩展,但我需要的是六号线覆盖。 有人可以帮我吗?即时通讯不是程序员,只是希望能够将文件发送到我自己的邮件,因为我需要以后在另一台计算机上打印它们。

对不起,我的英语。我不是以英语为母语的人。提前致谢!

回答

0

使用Arguments Property (WScript Object)

Arguments属性包含WshArguments对象( 收集的参数)。使用从零开始的索引从此集合检索 个别参数。

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 

如果使用文件(S)拖&下降以及

  • 使用SendTo…从右键菜单中的工作

    请检查Paul Sadowski的文章Sending email with CDO以简化您的代码。

  • +0

    非常感谢你,它的工作。我也会检查那篇文章。祝你今天愉快。 –

    相关问题