将excel pdf发送到邮件时无法关闭的窗口
因此,我发现一个宏将excel工作表导出为pdf,将该pdf发送到outlook的电子邮件地址,然后关闭outlook(如果宏打开了outlook)并删除pdf文件 我找到了我在右下方附上的代码将excel pdf发送到邮件时无法关闭的窗口,excel,email,pdf,window,vba,Excel,Email,Pdf,Window,Vba,因此,我发现一个宏将excel工作表导出为pdf,将该pdf发送到outlook的电子邮件地址,然后关闭outlook(如果宏打开了outlook)并删除pdf文件 我找到了我在右下方附上的代码 …在代码末尾,但这似乎不起作用。有没有人有过这方面的经验,并希望知道如何解决这一问题?我测试了您的代码,没有发现任何错误。但是,我发现没有必要通过各种调用使应用程序可见。因此我省略了它们。也许这就是你经历的原因。下面是我测试的代码 Sub SendPDF() Dim OutApp As Obj
…在代码末尾,但这似乎不起作用。有没有人有过这方面的经验,并希望知道如何解决这一问题?我测试了您的代码,没有发现任何错误。但是,我发现没有必要通过各种调用使应用程序可见。因此我省略了它们。也许这就是你经历的原因。下面是我测试的代码
Sub SendPDF()
Dim OutApp As Object
Dim IsCreated As Boolean
Dim PdfFile As String, Fn() As String
Dim Title As String
' ' Define PDF filename
Fn = Split(ActiveWorkbook.FullName, ".")
Fn(UBound(Fn)) = "pdf"
PdfFile = Join(Fn, ".")
' this code will not work if the file name includes a period:-
' PdfFile = ActiveWorkbook.FullName
' i = InStrRev(PdfFile, ".")
' If i > 1 Then PdfFile = Left(PdfFile, i - 1)
' PdfFile = PdfFile & ".pdf"
' Export activesheet as PDF
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=PdfFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
' Use already open Outlook if possible
On Error Resume Next
Set OutApp = GetObject(, "Outlook.Application")
If Err Then
Set OutApp = CreateObject("Outlook.Application")
IsCreated = True
End If
' OutApp.Visible = True ' you don't need this to be visible
' unless you want to edit before sending
On Error GoTo 0
' This is the tile of the email
Title = "Duty report " & Date
' Prepare e-mail with PDF attachment
With OutApp.CreateItem(0)
.Subject = Title
.To = "info@feam.be" ' <-- Put email of the recipient here
.Body = "Zie bijlage voor de duty report"
.Attachments.Add PdfFile
On Error Resume Next
.Send ' try to send
' Application.Visible = True ' appears not required
If Err Then
Title = "An error occurred." & vbCr & _
"The email wasn't sent."
Else
Title = "The mail was prepared successfuly." & vbCr & _
"It is now in your outbox."
End If
MsgBox Title, vbInformation, "Execution report"
End With
On Error GoTo 0
' Delete PDF file
Kill PdfFile
' Quit Outlook if it was created by this code
If IsCreated Then OutApp.Quit
' Release the memory of OutApp object variable
Set OutApp = Nothing
End Sub
Sub-SendPDF()
Dim OutApp作为对象
Dim被创建为布尔值
Dim PdfFile作为字符串,Fn()作为字符串
将标题设置为字符串
“”定义PDF文件名
Fn=Split(ActiveWorkbook.FullName,“.”)
Fn(UBound(Fn))=“pdf”
Pdfile=Join(Fn,“.”)
'如果文件名包含句点,则此代码将不起作用:-
'PdfFile=ActiveWorkbook.FullName
“i=InStrRev(Pdfile,”)
'如果i>1,则Pdfile=Left(Pdfile,i-1)
'PdfFile=PdfFile&“.pdf”
'将activesheet导出为PDF
ActiveSheet.ExportAsFixedFormat类型:=xlTypePDF_
文件名:=PdfFile_
质量:=xlQualityStandard_
IncludeDocProperties:=True_
IgnorePrintAreas:=假_
OpenAfterPublish:=False
'如果可能,请使用已打开的Outlook
出错时继续下一步
Set-OutApp=GetObject(,“Outlook.Application”)
如果有错误,那么
Set-OutApp=CreateObject(“Outlook.Application”)
IsCreated=True
如果结束
'OutApp.Visible=True'您不需要让它可见
'除非您要在发送前进行编辑
错误转到0
“这是电子邮件的互动程序
Title=“责任报告”和日期
'准备带有PDF附件的电子邮件
使用OutApp.CreateItem(0)
.主题=头衔
.To=”info@feam.be“'我试过你的代码,但现在我无法获得无法关闭的窗口。我读了你的评论,确实删除了那些行。实际上没有必要打开Outlook,因为它在这里是永久打开的。非常感谢!
ActiveWorkbook.Close True
Application.Quit
Sub SendPDF()
Dim OutApp As Object
Dim IsCreated As Boolean
Dim PdfFile As String, Fn() As String
Dim Title As String
' ' Define PDF filename
Fn = Split(ActiveWorkbook.FullName, ".")
Fn(UBound(Fn)) = "pdf"
PdfFile = Join(Fn, ".")
' this code will not work if the file name includes a period:-
' PdfFile = ActiveWorkbook.FullName
' i = InStrRev(PdfFile, ".")
' If i > 1 Then PdfFile = Left(PdfFile, i - 1)
' PdfFile = PdfFile & ".pdf"
' Export activesheet as PDF
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=PdfFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
' Use already open Outlook if possible
On Error Resume Next
Set OutApp = GetObject(, "Outlook.Application")
If Err Then
Set OutApp = CreateObject("Outlook.Application")
IsCreated = True
End If
' OutApp.Visible = True ' you don't need this to be visible
' unless you want to edit before sending
On Error GoTo 0
' This is the tile of the email
Title = "Duty report " & Date
' Prepare e-mail with PDF attachment
With OutApp.CreateItem(0)
.Subject = Title
.To = "info@feam.be" ' <-- Put email of the recipient here
.Body = "Zie bijlage voor de duty report"
.Attachments.Add PdfFile
On Error Resume Next
.Send ' try to send
' Application.Visible = True ' appears not required
If Err Then
Title = "An error occurred." & vbCr & _
"The email wasn't sent."
Else
Title = "The mail was prepared successfuly." & vbCr & _
"It is now in your outbox."
End If
MsgBox Title, vbInformation, "Execution report"
End With
On Error GoTo 0
' Delete PDF file
Kill PdfFile
' Quit Outlook if it was created by this code
If IsCreated Then OutApp.Quit
' Release the memory of OutApp object variable
Set OutApp = Nothing
End Sub