Export an excel dashboard in PDF based on a list of cells.

onche414

New Member
Joined
Aug 7, 2023
Messages
26
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I am pretty new to VBA and I am trying to learn how to work with it every since I am facing an issue on excel that can be automated (by mainly searching here some threads and managed to work my way until now).
Unfortunately, I have not found any similar solution to the issue I am facing now.

I have a dashboard on excel that is dynamic with values updating based on a list of cells (with checkbox). So on column "A" I have checkboxes and on Column "B" the name of the store (see print screen).
For example if I want the data to appear on the dashboard for the store "Ares", I click on the checkbox to the left on that store (which returns TRUE) and the dashboard gathers the data for that store from the other tabs.

1691415021839.png


What I want to do is to write a code which will select each store one by one and export the tab in PDF with the name of the store on a specific folder (example Ares.pdf). Here is the code that I have written but it is exporting the my own code in pdf. I am a beginner and I do not know how to resolve the issue.


VBA Code:
Sub ExportPDF()


Dim NamePDF As Worksheet
    
Set NamePDF = ActiveWorkbook.Sheets(1)
           
For i = 27 To 87
Cells(i, 1).Value = "True"
SName = NamePDF.Cells(i, 2)
 ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
         "\\Path" & SName, _
         Quality:=xlQualityStandard, IncludeDocProperties:=True, _
         IgnorePrintAreas:=False, OpenAfterPublish:=True

    Cells(i, 1).Value = "False"
Next i

End Sub
Can you please help me ?
Thank you,
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hello again,

I think my code is working but the issue now is that it cannot create the pdf and save it due to incorrect path.
If I only use this code with no path to a specific folder, it works but save the pdfs in random folder:

VBA Code:
Sub ExportPDF()


Dim NamePDF As Worksheet
    
Set NamePDF = ActiveWorkbook.Worksheets(1)
           
For i = 27 To 87
Cells(i, 1).Value = "True"
SName = NamePDF.Cells(i, 2)
 ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
         SName, _
         Quality:=xlQualityStandard, IncludeDocProperties:=True, _
         IgnorePrintAreas:=False, OpenAfterPublish:=True

    Cells(i, 1).Value = "False"
Next i

End Sub

But I want to specify the folder and when I do, I get a message :
1691421689231.png


Here is the code with the specification of folder:

VBA Code:
Sub ExportPDF()


Dim NamePDF As Worksheet
Dim path_PDF As String
Dim Sname As String

path_PDF = "Pathfolder\testtt"
    
Set NamePDF = ActiveWorkbook.Worksheets(1)
           
For i = 27 To 29
Cells(i, 1).Value = "True"
Sname = NamePDF.Cells(i, 2)
 ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
 Filename:=path_PDF & "\" & Sname, Quality:=xlQualityStandard, _
 IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
 True
  
    Cells(i, 1).Value = "False"
Next i

End Sub

Kindly help,
Thank you !
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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