Outlook 2010:自动打印附件特定的文件类型 [英] Outlook 2010 : Automatically printing attachments specific file types
问题描述
您好,
我有一个脚本可以自动打印谷歌附带的附件。
然而,它会自动打印签名附件以及任何附件,因为脚本只是指示打印附件。
是否有我可以滑动的其他代码,它将控制脚本只打印".pdf"," ; .doc"," .xls"," xlsx"和"docx"?
这会阻止规则打印其他任何内容吗?
脚本在下面.......不胜感激任何帮助! : - )
Sub LSPrint ( Item
as Outlook 。 MailItem )
-
On
错误 GoTo OError -
-        
'检测温度 -
Dim oFS
正如 FileSystemObject -
Dim sTempFolder
由于 字符串 -
设置 oFS
= 新 FileSystemObject -
'临时文件夹路径 -
sTempFolder
= oFS 。 GetSpecialFolder ( TemporaryFolder ) -
-      
'创建一个特殊的临时文件夹 -
cTmpFld
= sTempFolder
& " \ OETMP"
& 格式(现在,
" yyyymmddhhmmss" ;) -        
MkDir
( cTmpFld ) -        
-      
'save&打印 -   ;      
Dim oAtt
由于附件 -
对于
每个 oAtt 在项目。附件 - ;    
FileName
= oAtt 。 FileName -
FullFile
= cTmpFld
& " \"
& ; FileName -
-        
"保存附件" -
oAtt 。 SaveAsFile
( FullFile ) -
-        
'打印附件 -
设置 objShell
= CreateObject (" Shell.Application") -
设置 objFolder
= objShell .NameSpace(0) -
设置 objFolderItem
= objFolder 。 ParseName ( FullFile ) -        
objFolderItem 。 InvokeVerbEx
(" print") -
-        
下一步 oAtt -     
-      
'清理 -
如果
不 oFS
没什么 然后 设置 oFS
= 没有 -       
如果
不 objFolder
没有 然后
设置 objFolder =
没什么 -        
如果
不 objFolderItem
没有 然后
设置 objFolderItem =
没什么 -        
如果
不 objShell
没有 然后
设置 objShell =
没什么 -        
-      
OError < span lang ="EN-US"style ="font-family:'Courier New'; font-size:10pt">: -
如果 Err
<> 0
然后 - < span lang ="EN-US"style ="color:black; font-family:'Times New Roman','serif'; font-size:7pt">
MsgBox Err 。 Number
& " - "
& Err 。描述 - &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
Err 。清除 -   ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
结束
如果 - &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
退出
Sub
您好,
您可以检查文件名是否包含或以指定关键字结尾: " .pdf"," .doc"," .xls",
" xlsx"和"docx"。 VBA提供InStr函数r eturns一个整数,指定
在另一个字符串中第一次出现的起始位置。基本上你需要检查文件名字符串是否包含关键字,如果是,则跳过迭代。
您可以找到 获取
在Outlook 2010中开始使用VBA 文章有用跨度>
Hello,
I've got a script to automatically print attachments cribbed off google.
However, it automatically prints signature attachments as well as any attachment as the script just instructs to print the attachment.
Is there additional code I can slide in which will control the script to ONLY print ".pdf", ".doc", ".xls", "xlsx" and "docx"?
And will this stop the rule printing anything else?
Script is below.......be grateful for any help! :-)
Sub LSPrint(Item As Outlook.MailItem)
- On Error GoTo OError
- 'detect Temp
- Dim oFS As FileSystemObject
- Dim sTempFolder As String
- Set oFS = New FileSystemObject
- 'Temporary Folder Path
- sTempFolder = oFS.GetSpecialFolder(TemporaryFolder)
- 'creates a special temp folder
- cTmpFld = sTempFolder & "\OETMP" & Format(Now, "yyyymmddhhmmss")
- MkDir (cTmpFld)
- 'save & print
- Dim oAtt As Attachment
- For Each oAtt In Item.Attachments
- FileName = oAtt.FileName
- FullFile = cTmpFld & "\" & FileName
- 'save attachment
- oAtt.SaveAsFile (FullFile)
- 'prints attachment
- Set objShell = CreateObject("Shell.Application")
- Set objFolder = objShell.NameSpace(0)
- Set objFolderItem = objFolder.ParseName(FullFile)
- objFolderItem.InvokeVerbEx ("print")
- Next oAtt
- 'Cleanup
- 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
Hello,
You can check whether a file name contains or ends with the specified keywords: ".pdf", ".doc", ".xls", "xlsx" and "docx". VBA provides the InStr function which returns an integer specifying the start position of the first occurrence of one string within another. Basically you need to check whether the Filename string contains the keyword and skip the iteration if it does.
You may find the Getting Started with VBA in Outlook 2010 article helpful.
这篇关于Outlook 2010:自动打印附件特定的文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!