用于创建PDF的VBA代码 [英] VBA code to create PDF
本文介绍了用于创建PDF的VBA代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好任何人都可以帮我获取VBA代码在一个PDF文件中创建多个excel表格&一键单击附加为outlook附件
Hi Can any one help me to get VBA code create multiple excel sheet in one PDF file & attach as outlook attachment in one click
推荐答案
这是一个示例宏。你可以修改它以满足你的需要。
Here is a sample macro. You can modify it to suit your needs.
Sub SendPDF()
Dim strFile As String
Dim objOL As Object
Dim objMsg As Object
' Path and filename to use
strFile = "C:\Temp\MyFile.pdf"
' Select multiple sheets
Worksheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
' Save selected sheets as PDF
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFile
' Get Outlook - works best if Outlook is already running
On Error Resume Next
Set objOL = GetObject(Class:="Outlook.Application")
If objOL Is Nothing Then
Set objOL = CreateObject(Class:="Outlook.Application")
End If
On Error GoTo 0
' Create new message
Set objMsg = objOL.CreateItem(0) ' olMailItem
' Attach file
objMsg.Attachments.Add strFile
' Delete the file from disk (this is optional
Kill strFile
' Set subject
objMsg.Subject = "Monthly Report"
' Set body text
objMsg.Body = "Dear recipient," & vbCrLf & _
"The monthly report has been attached to this message." & vbCrLf & _
"Kind regards, Acne Inc."
' Set recipient
objMsg.To = "you@somewhere.com"
' Display the message
objMsg.Display
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation
End Sub
这篇关于用于创建PDF的VBA代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文