【发布时间】:2016-01-06 06:53:25
【问题描述】:
我的目标是能够单击一个按钮并将我的 Excel 工作表转换为我的电子表格范围,并将其通过电子邮件发送到工作表中一个单元格中的电子邮件地址。对于初学者,我有可以将一系列单元格转换为 PDF 文件并允许我保存它的代码:
Option Explicit
Sub savePDF()
Dim wSheet As Worksheet
Dim vFile As Variant
Dim sFile As String
Set wSheet = ActiveSheet
sFile = Replace(Replace(Range("D11"), " ", ""), ".", "_") _
& "_" _
& Range("H11") _
& ".pdf"
sFile = ThisWorkbook.Path & "\" & sFile
With Excel.Application.FileDialog(msoFileDialogSaveAs)
Dim i As Integer
For i = 1 To .Filters.Count
If InStr(.Filters(i).Extensions, "pdf") <> 0 Then Exit For
Next i
.FilterIndex = i
.InitialFileName = sFile
.Show
If .SelectedItems.Count > 0 Then vFile = .SelectedItems.Item(.SelectedItems.Count)
End With
If vFile <> "False" Then
wSheet.Range("A1:BF47").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=vFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End If
End Sub
任何人都可以操纵此代码(附加到按钮),以便它通过电子邮件发送电子邮件地址,该地址位于特定单元格中,当单击按钮时,作为额外的奖励,电子邮件的主题来自单元格也在电子表格中?
【问题讨论】:
-
也许见this?
-
这是我想要的区域,但不同之处在于我的 excel 表需要将 PDF 的 excel 表附加到电子邮件中,我不知道如何执行此操作。 @findwindow
-
@findwindow:我同意。该解决方案应该可以正常工作。此解决方案中唯一缺少的是将 PDF 文件添加为附件:
.Attachments.Add "C:\My Documents\" 'or vFile in the given solution在With语句中的MailItem。 -
对。这就是为什么我说也许在评论中看到这一点而不是提供答案,因为该链接不涵盖 pdf 部分。我相信有人会为此发布答案^_^就像我几天前所做的那样很容易链接^^