简体   繁体   English

宏将工作表格式化为xlsm而不是pdf

[英]Macros formatting worksheet as xlsm instead of pdf

I have created a macro that once a button is clicked on a worksheet a new Outlook email is generated with the worksheet as an attachment. 我创建了一个宏,一旦在工作表上单击一个按钮,就会生成一个新的Outlook电子邮件,并将该工作表作为附件。

When recording the macro and then looking at the format in the code it is saying pdf. 当记录宏,然后查看代码中的格式时,它说的是pdf。 When I trial the button the attachment is formatted as a xlsm. 当我尝试按钮时,附件被格式化为xlsm。

Sub email()
    ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "C:\Users\ROANDE~1\AppData\Local\Temp\Purchase Order Turkey MASTER Version 2.pdf" _
        , Quality:=xlQualityStandard, IncludeDocProperties:=False, _
        IgnorePrintAreas:=False, OpenAfterPublish:=False
    Application.Dialogs(xlDialogSendMail).Show
End Sub

I'm completely new to VBA. 我是VBA的新手。

Nice try. 不错的尝试。 :) but... :)但是...

Application.Dialogs(xlDialogSendMail).Show

...is the VBA equivalent of clicking FileSend (or Share in some versions), which opens an e-mail message in Microsoft Outlook with the current workbook attached. ...相当于在VBA中单击“ File →“ Send (或在某些版本中为“ Share ),这将在Microsoft Outlook中打开一个电子邮件,其中包含当前工作簿。

You have 2 lines of code there. 您在那里有两行代码。 The first line exports the Active Workbook to a PDF file located at C:\\Users\\ROANDE~1\\AppData\\Local\\Temp\\Purchase Order Turkey MASTER Version 2.pdf . 第一行将活动工作簿导出到位于C:\\Users\\ROANDE~1\\AppData\\Local\\Temp\\Purchase Order Turkey MASTER Version 2.pdf的PDF文件。

That is unrelated to the next line (a hint being a fact that the 2nd line doesn't mention a filename, variable, etc.). 那与下一行无关(提示是第二行没有提及文件名,变量等的事实)。

I'm always been a fan of the beginner technique of recording a macro doing what you want VBA to do, and then adjust as required, but some things do get missed (or ignored) by the Macro Recorder, probably like in this case. 我一直热衷于记录宏,以完成您希望VBA进行的操作,然后根据需要进行调整,但是,某些事情确实会被Macro Recorder遗漏(或忽略),就像在这种情况下一样。

1st, can you please confirm that the PDF exists (at the path above) and has the correct data that you want to email? 首先,您能否确认PDF存在(在上面的路径中)并且具有要通过电子邮件发送的正确数据? Also which version of Excel are you using? 您还使用哪个版本的Excel? (next time add the tag for your version when posting your question, like etc.) (下一次在发布问题时为您的版本添加标签,例如等。)

After that's steps verified working, we can move on to emailing the PDF... 经过验证的步骤可以正常工作后,我们可以继续通过电子邮件发送PDF ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM