我有一个功能(已从Ron DeBruin的网站取消),将活动或选定的工作表另存为pdf,并作为附件发送到Outlook中。它仍然适用于我给它的每个人,但是最近,它不适用于我的PC。我不断收到错误消息,好像VBA无法保存文件(由于路径无效或名称已被使用并且不想覆盖)
在运行Windows 10或Windows 7(在Win10上)的各种PC上运行时,我尝试将代码中的保存文件路径和文件名更改为更简单的内容,但仍然遇到相同的问题。我在另一台运行Windows 10的计算机上尝试了该文件,没有任何问题。我还尝试检查Microsoft加载项,一切都很好。
''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''
Sub RDB_Worksheet_Or_Worksheets_To_PDF_And_Create_Mail()
Dim FileName As String
If ActiveWindow.SelectedSheets.Count > 1 Then
MsgBox "There is more than one sheet selected," & vbNewLine & _
"be aware that every selected sheet will be published"
End If
'Call the function with the correct arguments
'Tip: You can also use Sheets("YourSheetName") instead of ActiveSheet in the code(sheet does not have to be active then)
FileName = RDB_Create_PDF(Source:=ActiveSheet, _
FixedFilePathName:="C:\Users\" & Environ("Username") & "\Documents\Container Shipment Reports\" & (Range("G4").Value) & ".pdf", _
OverwriteIfFileExist:=True, _
OpenPDFAfterPublish:=False)
'For a fixed file name use this in the FixedFilePathName argument
'FixedFilePathName:="C:\Users\Ron\Test\YourPdfFile.pdf"
If FileName <> "" Then
RDB_Mail_PDF_Outlook FileNamePDF:=FileName, _
StrTo:="XXXXXX.XXXXXXX@XXXXX.com.au", _
StrCC:="XXXXXX.XXXXXXX@XXXXX.com.au; XXXXXX.XXXXXXX@XXXXX.com.au", _
StrBCC:="", _
StrSubject:="Container Shipment Report " & (Range("G4").Value) & ".", _
Signature:=True, _
Send:=False, _
StrBody:="<body>Hello,</body><br>" & _
"<body>Please see the attached Container Shipment Report# " & (Range("G4").Value) & " from " & (Range("E4").Value) & "." & _
"<br><br>" & "Thank you.</body>"
Else
MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
"Microsoft Add-in is not installed" & vbNewLine & _
"You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
"The path to Save the file in arg 2 is not correct" & vbNewLine & _
"You didn't want to overwrite the existing PDF if it exists"
End If
Application.Quit
End Sub
''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''
这应该转换为PDF,附加到电子邮件,发送电子邮件,然后关闭Excel。目前,我只是从代码“无法创建PDF,可能的原因:等”中获得MsgBox响应。 (还有一个阻止excel文件保存的功能,因为它本来是一个空白模板。)正如我所说,这似乎仅在我的计算机上是一个问题,但在其他计算机上也可以使用,我认为这没有问题加上代码。