Macros – How to generate a report from a macro?

by May 9, 2023

In a previous post, I explained how we can schedule an automatic reverse-engineer from a database into a data model.

In this one, I’m sharing an example of a macro which allows you to generate a report from your model. All the other steps from the previous post can also be used with this macro.

The first step is to use the wizard to create a report as you want it and to save the settings for a Quick Launch.

Report Wizard Page 1

 

In the last page, you must save the settings:

Here is the macro you can use and customize to generate your report using the settings from the Quick Launch file:

'TITLE:  wGenerateReportHTML.BAS
'DESCRIPTION:  This macro generates a HTML report based on a quick launch file for a data model file

Option Explicit

Const PROJECT_FILENAME = "<YOUR_PATH><FILENAME>"
Const QUICK_LAUNCH_PATH = "%appdata%\Idera\ERStudio\XML\<QUICK_LAUNCH_FILENAME>.rpo"

'ER/Studio Variables
Dim diag As Diagram

Sub Main
	Debug.Clear

#Region "Get project"
	If (Not (DiagramManager.ActiveDiagram Is Nothing)) And (LCase(DiagramManager.ActiveDiagram.GetFullFilePath) = LCase(PROJECT_FILENAME)) Then
		Set diag = DiagramManager.ActiveDiagram
	Else
		' Load the dm1 file
		Set diag = DiagramManager.OpenFile(PROJECT_FILENAME)
	End If
#End Region

	If Not (diag Is NothingThen
		
		' Generate the report
		diag.GenerateReport(QUICK_LAUNCH_PATH)
		Debug.Print "Report generated"

		' Close the project
		DiagramManager.CloseDiagram(diag.FileName)
	Else
		Debug.Print "Project not found: ";PROJECT_FILENAME
	End If
End Sub

To use the above macro, you need to update the constants to match the path to your DM1 file and to your Quick Launch settings.

Then, you can run the macro from your ER/Studio Data Architect UI or from command line.

HTML report

Summary

In this blog post, we learned how to use:

Bonus

A short video which shows how to create a macro from a script in ER/Studio Data Architect: