我从来没有写过VBA代码,但我在网上查了一些信息。保存一个Excel文件并将其导出为PDF格式的另一张表
我的愿望如下:我有一个Excel文件3张。其中之一,我想添加一个按钮,它可以:
- 保存我的Excel文件遵循此命名约定的整体:
[name of a cells of a page]_AP_[date of today].xls
。 - 将其中一张纸保存在.pdf文件中。
- 调整内容时打印3张纸中的2张。
我已经开始了一些东西,但我真的不擅长编程:
Public Sub Savefile_Click() 'copie sauvegarde classeur
' save my file following a name
Dim nom As String
Dim chemin As String
Dim wSheet As Worksheet
chemin = "C:\Users\aaa\Desktop"
nom = [Q13].Value & "_" & Day(Date) & "-" & Month(Date) & "-" & Year(Date) _
& ".xlsm"
With ActiveWorkbook
.SaveAs Filename:=chemin & nom
.Close
rep = MsgBox("Fichier excell sauvegardé")
End With
' ... and print my active sheet (where the button will stay)
For Each wSheet In ActiveWorkbook.Worksheets
If wSheet.Visible Then wSheet.PrintOut
Next
'Save my page 'offre' in pdf on my desktop and print it
Worksheets("OFFRE A ENVOYER").Range("A1:i47").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=[Q13].Value & "_Offre de prix", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End Sub
后会有另一种选择和细节,但这是真正的基础。