VBA Code - print content on page

SuperSquirrel

New Member
Joined
Aug 18, 2017
Messages
9
So I have a spreadsheet that has a drop down of 300 schools.

Depending on what you select in that drop down, the table below magically updates using vlookups. There is a graph that is linked to that data.

https://ibb.co/jaeCKb

so the yellow is the drop down E2

The ask of me is to print (PDF) 300 graphs - one per school so schools know where they stand

my thought was to use VBA or a macro to print the page, then to navigate to the 2nd item in the drop down, print that, then navigate to the 3rd item, then print that, etc. etc.

I found this online:

Sub loopList()
Dim inputRange As range
'get the list of drop down list
Set inputRange = Evaluate(range("E2").validation.Formula1)
'loop the value in drop down list
For Each Cell In inputRange
'print to pdf
pdfName
= Cell.Value 'file name
fileSaveName
= Application.GetSaveAsFilename(pdfName, _
fileFilter
:="PDF Files (*.pdf), *.pdf")
If fileSaveName <> False Then
'active the sheet you want to print
ActiveWorkbook
.Sheets(pdfName).Activate
activeSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
fileSaveName _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
End If
Next
End Sub

but I don't know VBA, so I don't know how to make it work for me.

Using that, it works, for one. then crashes. It does not move to the 2nd option in the drop down

Also, that requires me to press "Enter" to save. It there a way for it to save automatically so I can press run and go to lunch and have everything saved, or do I have to press Enter 300 times?


Anywhoo -- experts please help this awesome vlookuper but horrible vbaer!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top