Excel · मराठी आवृत्ती
15.6 Stage 5 — Refresh आणि PDF macro
हा source macro refresh request करून Dashboard PDF export करतो. Platform/connectorनुसार async refreshचा behavior तपासल्याशिवाय याला सर्व data पूर्णपणे fresh असल्याची guarantee समजू नका.
Setup
- Practice workbook .xlsm म्हणून local writable folderमध्ये save करा.
- Developer › Visual Basic › Insert Moduleमध्ये code ठेवा.
- Dashboardवर “Refresh & Export PDF” shapeला RefreshAndExport assign करा.
- Print Area/page setup तयार करा; intended slicer selection स्पष्ट ठेवा.
Sub RefreshAndExport()
Dim pdfPath As String
On Error GoTo ErrHandler
ThisWorkbook.RefreshAll
Application.CalculateUntilAsyncQueriesDone
pdfPath = ThisWorkbook.Path & Application.PathSeparator & _
"Blinkit_Dashboard_" & Format(Date, "dd-mm-yyyy") & ".pdf"
ThisWorkbook.Worksheets("Dashboard").ExportAsFixedFormat _
Type:=xlTypePDF, Filename:=pdfPath, Quality:=xlQualityStandard, _
OpenAfterPublish:=True
MsgBox "Dashboard refreshed and saved as:" & vbCrLf & pdfPath, vbInformation
Exit Sub
ErrHandler:
MsgBox "Could not finish: " & Err.Description, vbExclamation
End Sub
वापरण्याआधी सुधारणा
ThisWorkbook.Pathरिकामा असल्यास स्पष्ट message देऊन Exit Sub करा. Error होण्याची वाट पाहू नका.- Cloud URL हा writable local folder path असेलच असं नाही; export destination validate करा.
- Same-date filename आधी असेल तर जुना output overwrite नको—unique timestamp किंवा user-approved destination वापरा.
- CalculateUntilAsyncQueriesDone सर्व connector/refresh typesसाठी पूर्ण barrier नाही. Query completion, Pivot refresh आणि final calculations verify झाल्यावर export करा.
- Refresh failureमुळे old data राहिलं असेल तर “successfully refreshed” message देऊ नका. Last successful source date तपासा.
Source example30September2026ला Blinkit_Dashboard_30-09-2026.pdf बनवतो. हा template filename आहे; report period आणि export date वेगळे असू शकतात.
Practice
काल्पनिक dataवर macro तपासा. _AllCities नाव तेव्हाच जोडा जेव्हा City filter खरोखर All आहे. PDF उघडून period, filters, totals आणि page count तपासा.