当我发送电子邮件时,它必须打印没有附件的发送电子邮件 [英] When I send a email it must print send email without the attachment

查看:104
本文介绍了当我发送电子邮件时,它必须打印没有附件的发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我发送电子邮件时,它必须在没有附件的情况下打印,但接收方必须打印电子邮件以及我正在开始工作的附件,但是我收到错误代码,如果我收到电子邮件时仍然需要424对象,但它仍然打印为我希望它如何工作所以当它关闭或处于睡眠模式时我不知道它是代码还是打印机。



when i send a email it must print without the attachment but the receiving must print the email aswell the attachments im getting to work but i get a error code were it says 424 object required when i get receiving emails but it still printing as how i want it to work so i don't know if it is the code or the printer when it is off or in sleep mode.

Private 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
 
Private WithEvents Items As Outlook.Items
 
Private Sub Application_Startup()
  Dim Ns As Outlook.NameSpace
  Dim Folder As Outlook.MAPIFolder
 
  Set Ns = Application.GetNamespace("MAPI")
  Set Folder = Ns.GetDefaultFolder(olFolderSentMail)
  Set Items = Folder.Items
End Sub
 
Private Sub Items_ItemAdd(ByVal Item As Object)
  If TypeOf Item Is Outlook.MailItem Then
      Item.PrintOut
    
  End If
End Sub

Sub attachmentPrint(Item As Outlook.MailItem)

On Error GoTo OError

' This script finds the system's Temp folders,
' saves any attachments, and runs the Print
' command for that file.

    Dim ofs As FileSystemObject
    Dim sTempFolder As String
    Set ofs = New FileSystemObject
    sTempFolder = ofs.GetSpecialFolder(TemporaryFolder)

    cTmpFld = sTempFolder & "\OETMP" & Format(Now, "yyyymmddhhmmss")
    MkDir (cTmpFld)
    
    ' in the next few lines, you'll see an entry that
    ' says FileType = . This line gets the last 4
    ' characters of the file name, which we'll use later.

    Dim oAtt As Attachment
    For Each oAtt In Item.Attachments
        FileName = oAtt.FileName
        FileType = LCase$(Right$(FileName, 4))
        FullFile = cTmpFld & "\" & FileName
        oAtt.SaveAsFile (FullFile)
        
        ' We're using the FileType text. Note that it's the
        ' last 4 characters of the file name, which is why
        ' the next chunk has .xls and xlsx (without the period)
        ' - the period counts as the fourth character.
        ' Insert any file extensions you want printed.

        Select Case FileType
        Case ".doc", "docx", ".xls", "xlsx", ".ppt", "pptx", ".pdf"
            Set objShell = CreateObject("Shell.Application")
            Set objFolder = objShell.NameSpace(0)
            Set objFolderItem = objFolder.ParseName(FullFile)
            objFolderItem.InvokeVerbEx ("print")
        End Select
    Next oAtt


    If Not ofs Is Nothing Then Set ofs = Nothing
    If Not objFolder Is Nothing Then Set objFolder = Nothing
    If Not objFolderItem Is Nothing Then Set objFolderItem = Nothing
    If Not objShell Is Nothing Then Set objShell = Nothing

OError:
    If Err <> 0 Then
        MsgBox Err.Number & " - " & Err.Description
        Err.Clear
    End If
    
Exit Sub
End Sub





我尝试了什么:



i试图制作一个作为模块,一个作为应用程序,但没有运气我甚至试图在规则中指定

打印设置勾选一个框以自动打印附件

工作但也发送时不想打印附件发送时只接收



What I have tried:

i have tried to make one as module and one as the app but no luck i even tried to specify in the rules
print settings tick a box to print attachments automatically
working but also on sending don't want to print attach on sending only on receiving

推荐答案

(右


(FileName,4))
FullFile = cTmpFld& \& FileName
oAtt.SaveAsFile(FullFile)

'我们正在使用FileType文本。请注意,这是
'文件名的最后4个字符,这就是为什么
'下一个块有.xls和xlsx(没有句号)
' - 这个时期算作第四个字符。
'插入您要打印的任何文件扩展名。

选择案例文件类型
案例.doc,docx,。xls,xlsx,。ptt,pptx,。pdf
设置objShell = CreateObject(Shell.Application)
设置objFolder = objShell.NameSpace(0)
设置objFolderItem = objFolder.ParseName(FullFile)
objFolderItem.InvokeVerbEx(print)
结束选择
下一个oAtt


如果Not ofs Nothing则Set ofs = Nothing
如果不objFolder则没有那么设置objFolder = Nothing
如果不是objFolderItem则Nothing然后设置objFolderItem = Nothing
如果Not objShell是Nothing则设置objShell = Nothing

OError:
如果Err<> 0然后
MsgBox Err.Number& - & Err.Description
Err.Clear
结束如果

退出Sub
End Sub
(FileName, 4)) FullFile = cTmpFld & "\" & FileName oAtt.SaveAsFile (FullFile) ' We're using the FileType text. Note that it's the ' last 4 characters of the file name, which is why ' the next chunk has .xls and xlsx (without the period) ' - the period counts as the fourth character. ' Insert any file extensions you want printed. Select Case FileType Case ".doc", "docx", ".xls", "xlsx", ".ppt", "pptx", ".pdf" Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.NameSpace(0) Set objFolderItem = objFolder.ParseName(FullFile) objFolderItem.InvokeVerbEx ("print") End Select Next oAtt If Not ofs Is Nothing Then Set ofs = Nothing If Not objFolder Is Nothing Then Set objFolder = Nothing If Not objFolderItem Is Nothing Then Set objFolderItem = Nothing If Not objShell Is Nothing Then Set objShell = Nothing OError: If Err <> 0 Then MsgBox Err.Number & " - " & Err.Description Err.Clear End If Exit Sub End Sub





我尝试了什么:



i试图制作一个作为模块,一个作为应用程序,但没有运气我甚至试图在规则中指定

打印设置勾选一个框以自动打印附件

工作但也发送时不希望打印附件仅在接收时发送



What I have tried:

i have tried to make one as module and one as the app but no luck i even tried to specify in the rules
print settings tick a box to print attachments automatically
working but also on sending don't want to print attach on sending only on receiving


这是一个非常奇怪的要求,几乎不可能在组织外执行。你将这个问题标记为C#,但你的代码是VBA。



我能想到的唯一方法就是使用VSTO创建两个附加组件外表。您可以在演练:创建您的第一个应用程序级添加主题的介绍中看到-in for Outlook [ ^ ]



您必须在两侧安装附加组件,发送方和接收方,两者都必须使用外表。如果接收者在你的组织之外,那么让这个人安装一个附加组件只是为了接收你的电子邮件,祝你好运。



我的第一个建议是步骤回来看看为什么你首先尝试这个。如果您的唯一答案是因为它是必需的,那么您需要查看您的要求。因为这个要求几乎不可能以任何正确的形式或方式实现。
That is a extremely odd requirement and one that will be nearly impossible to enforce outside an organization. You tag this question as C#, but your code is VBA.

The only way I can think of to even attempt this is using VSTO to create two add-ons for Outlook. You can see in introduction to the topic Walkthrough: Creating Your First Application-Level Add-in for Outlook[^]

You will have to install the add-ons on both sides, the sender and receiver, and both will have to be using Outlook. If the receiver is outside your organization good luck getting that person to install an add-on just to receive emails from you.

What my first suggestion would be is to step back and look at why you are attempting this in the first place. If your only answer is because it is required then you need to look at your requirements. Because that requirement is almost impossible to implement in any correct form or fashion.


这篇关于当我发送电子邮件时,它必须打印没有附件的发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆