Functions
mdlVBAFunctions

Functions

int mdlVBA_parseMacroSpecification (ParsedMacroSpecification *pResult, WCharP pSpecification)
 Parses the macro specification. More...
 
void mdlVBA_getLastError (VbaInterfaceError *pVBAInterfaceCode, int *pSDKCode)
 Retrieves the last error code. More...
 
bool mdlVBA_isIdeVisible ()
 Gets whether the VBE Editor is displayed. More...
 
int mdlVBA_runMacro (WCharCP pProjectName, WCharCP pModule, WCharCP pMacro)
 Runs the specified macro. More...
 
int mdlVBA_runProcedure (WCharP pResult, int resultLength, WCharCP pProjectName, WCharCP pModuleName, WCharCP pProcedureName, int nArguments, WChar const **pArguments)
 Runs a Sub or Function. More...
 
int mdlVBA_executeLine (WCharCP pProjectName, WCharCP pLine)
 Executes a line of VB code just like it was typed into the immediate window of the VBA Editor. More...
 
int mdlVBA_showMacrosDialog ()
 Shows the macros dialog for all projects. More...
 
int mdlVBA_showProjectMacrosDialog (WCharCP pProjectName)
 Shows the macros dialog for a specific project. More...
 
void mdlVBA_getMacroArgument (WChar *pBuffer, int maxCharacters)
 Gets the value that the Application.KeyinArguments property returns. More...
 
void mdlVBA_setMacroArgument (WCharCP pBuffer)
 Sets the value that the Application.KeyinArguments property returns. More...
 
int mdlVBA_loadProject (WCharCP pFileName)
 Loads a VBA project. More...
 
int mdlVBA_unloadProject (WCharCP pProjectName)
 Unloads a VBA project. More...
 
void mdlVBA_reportCurrentError ()
 Displays an error message that describes the result of the last VBA command or call to an mdlVBA_ function. More...
 
void mdlVBA_reportParseError (WCharCP pProjectName)
 Displays an error message that describes the syntax error that mdlVBA_executeLine detected. More...
 

Detailed Description

Function Documentation

int mdlVBA_executeLine ( WCharCP  pProjectName,
WCharCP  pLine 
)

Executes a line of VB code just like it was typed into the immediate window of the VBA Editor.

Parameters
[in]pProjectNamepoints to the name of the project to use as an execution context; can be NULL
[in]pLinepoints to the line of VBA code
Remarks
mdlVBA_executeLine executes the line in the context of a project. If pProject is NULL, then mdlVBA_executeLine picks the project randomly. That is okay if the line of VBA code only refers to symbols defined in MicroStation's object model. It can lead to unpredictable results if the line of VB code refers to symbols that are defined by one of the projects.
if pProject is not NULL and there is no project loaded with the specified name, mdlVBA_executeLine tries to load the project.
Call mdlVBA_reportCurrentError to display an appropriate error message if mdlVBA_executeLine fails.
See also
mdlVBA_parseMacroSpecification
mdlVBA_runMacro
mdlVBA_runProcedure
Returns
E_VBAINTERFACE_NO_ERROR if successful; E_VBAINTERFACE_CANNOT_FIND_PROJECT_FILE if it could not find the specified project; E_VBAINTERFACE_PARSE_LINE_ERROR if there was an error parsing the line; or E_VBAINTERFACE_RUNTIME_ERROR if there was a error executing the line even though it parsed successfully.
Remarks
Required Library: mdlbltin.lib
void mdlVBA_getLastError ( VbaInterfaceError pVBAInterfaceCode,
int *  pSDKCode 
)

Retrieves the last error code.

Parameters
[in]pVBAInterfaceCodePoints to location to receive MicroStation's VBA error code
[in]pSDKCodePoints to location to receive the last error code from the VBA SDK.
Remarks
Required Library: mdlbltin.lib
void mdlVBA_getMacroArgument ( WChar *  pBuffer,
int  maxCharacters 
)

Gets the value that the Application.KeyinArguments property returns.

Parameters
[out]pBufferThe contents of Application.KeyinArguments are copied to this location
[in]maxCharactersSpecifies the size of the space pBuffer points to
Remarks
Required Library: mdlbltin.lib
bool mdlVBA_isIdeVisible ( )

Gets whether the VBE Editor is displayed.

Returns
true if the IDE is displayed; false otherwise
Remarks
Required Library: mdlbltin.lib
int mdlVBA_loadProject ( WCharCP  pFileName)

Loads a VBA project.

Parameters
[in]pFileNameThe name of the file that contains the project.
Returns
E_VBAINTERFACE_NO_ERROR if successful; E_VBAINTERFACE_CANNOT_FIND_PROJECT_FILE; if it cannot find the file; E_VBAINTERFACE_LOAD_PROJECT if there is an error with the project file; or E_VBAINTERFACE_PROJECT_ALREADYLOADED if the project is already loaded.
Remarks
pFileName can point to any part of the file name. mdlVBA_loadProject appends ".mvba" if the project name does not contain a suffix. It also searches all of the directories specified by the configuration variable MS_VBASEARCHDIRECTORIES.
Call mdlVBA_reportCurrentError to display an appropriate error message if mdlVBA_loadProject fails.
Required Library: mdlbltin.lib
int mdlVBA_parseMacroSpecification ( ParsedMacroSpecification pResult,
WCharP  pSpecification 
)

Parses the macro specification.

Parameters
[out]pResultThe results of parsing are stored here.
[in]pSpecificationA standard macro specification.
Remarks
mdlVBA_parseMacroSpecification parses the string pSpecification points to and stores the result in the structure pResult points to. mdlVBA_parseMacroSpecification overwrites part of the string, storing zeroes at the end of the project name, the end of the module name, and the end of the macro name.
The format of the specification is [projectName]moduleName.macroName arguments. The project name, module name, and arguments are all optional. Only use the square brackets when specifying the project name. Only use the dot when specifying the module name.
If the input string specifies a project, mdlVBA_parseMacroSpecification sets pResult->pProject to point to the project name in the input string and stores a 0 at the end of the project name. If the input string does not specify a project name, then mdlVBA_parseMacroSpecification sets pResult->pProject to NULL. Likewise, it sets pModule and pUnparsed to NULL or to the appropriate locations in the string pSpecification points to.
The macro name is the only required part of the specification. If mdlVBA_parseMacroSpecification does not find a macro name, it sets pResult->pMacro to NULL and returns ERROR.
To specify a macro named ShowRange in a project named Utilities and in a module named modMain, specificy [Utilities]modMain.ShowRange. If the project is already loaded, and none of the loaded projects have a macro named ShowRange, then the specification ShowRange is enough. Other legal specifications are [Utilities]ShowRange and modMain.ShowRange. Given a specification like [Utilities]ShowRange 13213, pResult->pProject will point to Utilities, pModule will be NULL, pMacro will point to ShowRange, and pUnparsed will point to 13213
Returns
SUCCESS if it successfully parsed the specification; ERROR otherwise. It sets pResult->pMacro to NULL whenever it returns ERROR.
Remarks
Required Library: mdlbltin.lib
See also
mdlVBA_runMacro
mdlVBA_runProcedure
void mdlVBA_reportCurrentError ( )

Displays an error message that describes the result of the last VBA command or call to an mdlVBA_ function.

Remarks
Required Library: mdlbltin.lib
void mdlVBA_reportParseError ( WCharCP  pProjectName)

Displays an error message that describes the syntax error that mdlVBA_executeLine detected.

Parameters
[in]pProjectNameThis should be the same name that was passed to mdlVBA_executeLine
Remarks
Required Library: mdlbltin.lib
int mdlVBA_runMacro ( WCharCP  pProjectName,
WCharCP  pModule,
WCharCP  pMacro 
)

Runs the specified macro.

Parameters
[in]pProjectNamespecifies the project to search for the macro. If NULL, all projects are searched.
[in]pModulespecifies the module to search for the macro. If NULL, all modules are searched.
[in]pMacrospecifies the name of the macro
Returns
Returns SUCCESS if the project ran successfully. It returns an error code otherwise.
Remarks
This is similar to executing a VBA RUN command to run a macro. Use mdlVBA_setMacroArgument to set that the macro will get if it uses Application.KeyinArguments.
if pProject is not NULL and there is no project loaded with the specified name, mdlVBA_runMacro tries to load the project.
Call mdlVBA_reportCurrentError to display an appropriate error message if mdlVBA_runProcedure fails.
See also
mdlVBA_parseMacroSpecification
mdlVBA_runProcedure
mdlVBA_executeLine
mdlVBA_setMacroArgument
Remarks
Required Library: mdlbltin.lib
int mdlVBA_runProcedure ( WCharP  pResult,
int  resultLength,
WCharCP  pProjectName,
WCharCP  pModuleName,
WCharCP  pProcedureName,
int  nArguments,
WChar const **  pArguments 
)

Runs a Sub or Function.

Parameters
[in]pResultpoints to a buffer that gets a string representation of the result; NULL is allowed
[in]resultLengthsize of the buffer that gets the result.
[in]pProjectNamespecifies the project to search for the macro. If NULL, all projects are searched.
[in]pModuleNamespecifies the module to search for the macro. If NULL, all modules are searched.
[in]pProcedureNamespecifies the name of the procedure
[in]nArgumentsnumber of arguments to pass to the procedure
[in]pArgumentsan array of arguments
Returns
Returns SUCCESS if the project ran successfully. It returns an error code otherwise.
Remarks
The arguments are all supplied to mdlVBA_runProcedure as strings, but mdlVBA_runProcedure converts the strings to the data types that the procedure expects. It is possible to use this technique to call a procdure that takes Double, Long, Integer, and String arguments. It is also possible to use this procedure to get a Double, Long, Integer, or String return value.
if pProject is not NULL and there is no project loaded with the specified name, mdlVBA_runProject tries to load the project.
Call mdlVBA_reportCurrentError to display an appropriate error message if mdlVBA_runProcedure fails.
See also
mdlVBA_parseMacroSpecification
mdlVBA_runMacro
mdlVBA_executeLine
Remarks
Required Library: mdlbltin.lib
void mdlVBA_setMacroArgument ( WCharCP  pBuffer)

Sets the value that the Application.KeyinArguments property returns.

Parameters
[in]pBufferContents of this string are copied.
Remarks
Required Library: mdlbltin.lib
int mdlVBA_showMacrosDialog ( )

Shows the macros dialog for all projects.

Returns
SUCCESS if it was able to display the dialog; false otherwise.
Remarks
This displays the same dialog box MicroStation displays when the user clicks on the Macros.. button in the VBA Project Manager
This is a modal operation. It opens a modal dialog box and does not return until some user operation closes the dialog box.
Required Library: mdlbltin.lib
int mdlVBA_showProjectMacrosDialog ( WCharCP  pProjectName)

Shows the macros dialog for a specific project.

Parameters
[in]pProjectNameSpecifies a project
Returns
SUCCESS if it was able to display the dialog; false otherwise.
Remarks
This displays the same dialog box MicroStation displays when the user double clicks on one of the projects in the VBA Project Manager
This is a modal operation. It opens a modal dialog box and does not return until some user operation closes the dialog box.
Required Library: mdlbltin.lib
int mdlVBA_unloadProject ( WCharCP  pProjectName)

Unloads a VBA project.

Parameters
[in]pProjectNameThis may be the project name or the name of the file that contains the project. If it is the file name, it must be the full name. Case is ignored for both project name and file name.
Returns
E_VBAINTERFACE_NO_ERROR if successful; E_VBAINTERFACE_PROJECT_NOT_OPEN if pName does not match any of the loaded projects; or E_VBAINTERFACE_UNLOAD_FAILED if it finds project but cannot unload it.
Remarks
mdlVBA_unloadProject cannot unload a project if any loaded project has a reference to it.
Call mdlVBA_reportCurrentError to display an appropriate error message if mdlVBA_loadProject fails.
Required Library: mdlbltin.lib

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.