保存excel发票作为基于2单元格的xlsm和pdf,然后打印…解决scheme

我的目的是在一个按下的excel发票上打印一个button,打印发票,保存到xlsm,保存为pdf(两个单元格都存有自动名称,发票号码和客户名称),然后closures工作簿。

我已经search了低和高的答案,但只有在单独的元素find帮助。

文件名所需的单元格是C18和A7。

谢谢Peh教我礼节。 这是我的问题的答案 –

这里是代码 – (请阅读标记为“了解每个位都做什么”的评论)

Sub SaveandPrint() 'this is the macro's name Dim FileName As String Dim Path As String ActiveSheet.PrintOut 'this bit prints the sheet Application.DisplayAlerts = False Path = "C:\add\your\file\destination\here" 'Change the directory path here where you want to save the file FileName = Range("C18").Value & " " & Range("A7").Value & ".xlsm" 'Change extension here for different excel formats. 'Also, change range cell values to select different cell value for naming ActiveWorkbook.SaveAs Path & FileName, xlOpenXMLWorkbookMacroEnabled 'Change the format here which matches with the extension above. 'Choose from the following link http://msdn.microsoft.com/en-us/libr.../ff198017.aspx Application.DisplayAlerts = True Dim fName As String 'this is the saving to pdf bit fName = Range("C18").Value & " " & Range("A7").Value 'again, change cells to C18 and A7 to the ones you want to name file ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _ "C:\add\your\file\destination\here" & fName, Quality:=xlQualityStandard, _ 'change destination folder IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False ActiveWorkbook.Close 'closes the workbook End Sub 

希望这会有所帮助,并节省一些时间,让我血腥的年龄,把我的头围绕它实施!