This loops through a list of students, but fails on the print area, which is set and coded in the export line - it prints 130 pages for each student when it should only be one. All the printer gets called which opens a dialogue box (login 6 password) and that stops the macro - the printer is a workprinter on a network which is not always available.
Is there a way to stop the printer getting called?
And controlling the pages to the print area?
Option Explicit
Sub PdfExportMacro()
Dim rCell As Range, rRng As Range
'Student numbers in cells A7:A160
Set rRng = Worksheets("studentlist").Range("A7:A160") '<--| set your "students" range
With Worksheets("Feedback") '<--| reference "Feedback" worksheet
For Each rCell In rRng '<--| loop through "students" range
.Range("A1").Value = rCell.Value '<--| write current student number to cell A1 on Feedback sheet
' Export & save file as pdf using SNum as filename:
.ExportAsFixedFormat Type:=xlTypePDF, fileName:= _
"Macintosh HD:Users:Michael:Desktop:" & rCell.Value, Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Next rCell
End With
End Sub
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…