我已经制作了一个宏来定义每个页面的打印区域,然后将所有纸张保存为PDF。
但每次运行宏时,都会出现错误,表示名称Print_area
已被占用,我需要更换另一个名称Print_area
。并且错误框出现在最开始,所以我认为这个问题只与某些事物的定义有关。否则,它一开始就不能那么快。
我在代码中没有将任何名称定义为Sub SaveTable()
Dim newFile
Dim myWorkbook As String
AreaToPrint
myWorkbook = ActiveWorkbook.Name
Application.Calculation = xlCalculationAutomatic
'To creat a new Workbook just in case that the new one will take place
'of my "model" Excel.
Dim NewObject As Object
Set NewObject = CreateObject("Scripting.FileSystemObject")
'The adress has already been defined before:
If NewObject.FolderExists(Adress) Then
'Save as new workbook
newFile = Adress + "\" + myWorkbook + ".xlsm"
'Save as PDF
newFile = Adress + "\" + myWorkbook + ".pdf"
ActiveWorkbook.ExportAsFixedFormat Type:=x1TypePDF, _
Filename:=mewFile, _
Quality:=x1QualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End If
End Sub
'For example, I have two sheets in one workbook, then I define their
'area of print seperately:
Sub AreaToPrint()
ActiveWorkbook.Sheets("AAA").PageSetup.PrintArea = "$A$1:$C$10"
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Application.PrintCommunication = True
ActiveWorkbook.Sheets("BBB").PageSetup.PrintArea = "$A$1:$C$10"
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Application.PrintCommunication = True
End Sub
:
Print_area
此代码已经过简化,但总体思路是相同的。
每次都会显示“重复名称”的错误,并且在名称gestion的部分中,我没有看到任何人{{1}}。如果您有任何想法,请留言。谢谢。