Automating features |
Top Previous Next |
VS VBA For VBA and Visual Studio, several features of MZ-Tools can be automated from an external script. Unfortunately, VB6 cannot be automated directly. Some scenarios or features where you may want to use external automation are:
For VBA, to automate MZ-Tools you need:
The list of commands that can be automated is the following:
Here you have a Visual Basic Script (.vbs) that automates Microsoft Access to add line numbers to a database file: Const officeProgId = "Access.Application" Const addinProgId = "MZTools8VBA" Const commandName = "MZTools8.AddLineNumbers"
Dim fso Dim app Dim addIn Dim addInObject Dim officeFile Dim logFile Dim commandLineArgs
' Set variables officeFile = "C:\Users\Public\DatabaseAutomation.accdb" logFile = "C:\Users\Public\MZTools8.log" commandLineArgs = logFile
' Delete files if they exist Set fso = CreateObject("Scripting.FileSystemObject") If fso.FileExists(logFile) Then fso.DeleteFile(logFile) End If
' Open the Office document Set app = CreateObject(officeProgId) app.OpenCurrentDatabase(officeFile)
' Make Office and VBA editor visible app.Visible = True app.VBE.MainWindow.Visible = True
' Get the MZ-Tools add-in Set addIn = app.VBE.AddIns.Item(addinProgId)
' Ensure it is loaded addIn.Connect = True
' Get its inner object Set addInObject = addIn.Object
' Execute the command Call addInObject.ExecuteCommand(commandName, commandLineArgs)
' Exit the Office application app.Quit
WSCript.Echo "Done"
For Visual Studio, to automate MZ-Tools you need:
For Visual Studio 2015 and higher the list of commands that can be automated is the following:
For Visual Studio 2013 and lower the list of commands that can be automated is the following:
Here you have a Visual Basic Script (.vbs) that automates Visual Studio 2017 to get the results of the Quality Review feature: Const progId = "VisualStudio.DTE.15.0" ' VS 2017 Const commandName = "MZTools.ReviewQuality"
Dim fso Dim dte Dim solution Dim logFile Dim outputFile Dim commandLineArgs
' Set variables solution= "C:\Users\Public\MySolution\MySolution.sln" logFile = "C:\Users\Public\MZTools8.log" outputFile = "C:\Users\Public\MZTools8QualityReviewResult.txt" commandLineArgs = logFile & " " & outputFile
' Delete files if they exist Set fso = CreateObject("Scripting.FileSystemObject") If fso.FileExists(logFile) Then fso.DeleteFile(logFile) End If If fso.FileExists(outputFile) Then fso.DeleteFile(outputFile) End If
' Open the solution Set dte = CreateObject(progId) dte.Solution.Open(solution)
' Make the IDE visible dte.MainWindow.Visible = True
' Execute the command Call dte.ExecuteCommand(commandName, commandLineArgs)
' Exit the IDE dte.Quit
WSCript.Echo "Done" |