I've been struggling on one-click sharing file with email attachment to colleagues -- by default it'll always lead to an Email in plain text without signature, and always with the prefix "ready to share....".
Below link mentioned something, but not fulfill my target.
Courtesy of [Joseph's Script Method] I searched, i found that there is a VBS way out, and i am trying to accomplish that into a DOpus button (instead of right-click -> send to)
BTW: a very similar approach discovered here, but no further progress. and I've achieved much more...
Email selected files with Outlook. Code provide, need help with creating a button
What i did -- Approach A:
i created a button with very simple command:
and of course I put the script at the correct place. and it works!
Sadly, it only works with single files, and if I've selected multiple, a lot of mails will jump out.
What i did -- Approach B: VBS in DO CommandButton
I created a button with VBS as below:
Option Explicit Function OnClick(ByRef clickData) DOpus.ClearOutput Dim cmd, lister, tab, selItem, folderEnum, folderItem ' --------------------------------------------------------- Set cmd = clickData.func.command cmd.deselect = false ' Prevent automatic deselection Dim OutApp, oNameSpace, oInbox, oEmailItem, olMailItem Dim a, oAttachments, subjectStr, olFormatHTML Dim objFSO,strSigFilePath, objSignatureFile, strBuffer, strText olMailItem = 0 olFormatHTML = 2 Set OutApp = CreateObject("Outlook.Application") 'opens Outlook Set oEmailItem = OutApp.CreateItem(olMailItem) 'opens new email Const LineBreak = "<br>" DOpus.Output "Selected items in " & clickData.func.sourcetab.path & ":" If clickData.func.sourcetab.selected.count = 0 Then DOpus.Output " (none)" Exit function Else For Each selItem in clickData.func.sourcetab.selected If (selItem.is_dir) Then DOpus.Output " (d) " & selItem.RealPath Else DOpus.Output " (f) " & selItem.RealPath Set oAttachments = oEmailItem.Attachments.Add(selItem.RealPath) subjectStr = subjectStr & Right(selItem.RealPath,Len(selItem.RealPath)-(InStrRev(selItem.RealPath,"\"))) & ", " strText=strText & LineBreak & Right(selItem.RealPath,Len(selItem.RealPath)-(InStrRev(selItem.RealPath,"\"))) End If Next End If DOpus.Output clickData.func.sourcetab.selected(0).RealPath Set objFSO = CreateObject("Scripting.FileSystemObject") strSigFilePath = "C:\Users\huangb\AppData\Roaming\Microsoft\Signatures\" Set objSignatureFile = objFSO.OpenTextFile(strSigFilePath & "Short_en.htm") strBuffer = objSignatureFile.ReadAll objSignatureFile.Close oEmailItem.Subject = "FileSharing: " & Left(subjectStr, len(subjectStr)-2) oEmailItem.BodyFormat = olFormatHTML oEmailItem.HTMLBody = "Please check attachment: " & strText & ". " & LineBreak & LineBreak & strBuffer oEmailItem.Display End Function
it also works, mostly...
When the code runs into the add attachment line, it failed.
Set oAttachments = oEmailItem.Attachments.Add(selItem.RealPath)
the compiler simply said "the operation failed"
but if I skip this line, everything works perfectly.
However, I am quite convinced that the syntax was correct (in VB & windows world).
Could anybody help me here, please?