Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
MicroStation
  • Product Communities
MicroStation
[Archived] AskInga Wiki Run a VBA macro when opening or closing design files
    • Sign In

    • -AskInga
      • +3D MicroStation
      • +AccuDraw Secrets
      • +Animation - Rendering
      • +Behind The Scenes
      • +Cells
      • +Colours
      • +Conversion - Translation
      • +Coordinate Input
      • +Design Settings
      • +Dimensions
      • +DWG
      • +EDG
      • +Element Manipulation
      • +Element Properties
      • +Element Selection
      • +Freeware - Shareware
      • +Interface Look And Feel
      • +Internet - E-Links - Links
      • +Keyins
      • +Levels
      • +Line Styles
      • +Models
      • +MSM Archive
      • +Other
      • +Presentations
      • +Printing - Plotting
      • -Programming - Automation
        • Run a VBA macro when opening or closing design files
        • Run commands or BASIC macro when opening files
        • Run commands when starting MicroStation
        • The Settings Manager - Part 1
        • The Settings Manager - Part 2
      • +Rasters - Images
      • +References
      • +Tags - Data Fields - Fields
      • +Text - Fonts - Annotation
      • +Views
      • +Windows - Interacting With
      • +Workspaces - Configuration
    • graffiti

     
     Questions about this article, topic, or product? Click here. 

    Run a VBA macro when opening or closing design files

    AskInga logo

    Original Article Date: January 2004 

    Updated:  December 2010

    Gerald Hernandez, president of Geospatial Paradigm Solutions, Inc., contributed this slick VBA macro that will execute a set of commands every time a design file is opened and/or closed in MicroStation V8. He also discusses how to customize this little application to suit your own needs. Very Cool! 


    In response to a recent posting on Bentley's discussion groups, I prepared a VBA macro that executes a set of commands upon opening and closing design files. You are free to download the AutoRun.mvba project and modify to suit your needs. This macro was intentionally written using VBA equivalents of familiar MBE (MicroStation Basic Extensions) style commands to execute standard MicroStation key-ins. This is to aid those who are familiar with key-in scripts and/or MBE to make the transition to VBA.

    This sample will by no means teach you VBA, but hopefully you will notice your wealth of scripting knowledge is still valuable. In addition, it makes the code very short and understandable to almost anyone. The code is also heavily commented with just about everything you need to know.

    The sample macro with this article performs the following functions:

    Upon opening a file:
    It will close all views except for View 1, maximize the size of View 1 and finally executes a Fit All command.

    Upon closing a file:
    It will detach any and all reference files.

    Of course the idea is that you could customize this macro to perform just about any thing you like. The section of particular interest will be the following methods in the clsDGNOpenClose Class:


    Private Sub m_OpenCloseHooks_OnDesignFileOpened(ByVal DesignFileName As String)

    Private Sub m_OpenCloseHooks_OnDesignFileClosed(ByVal DesignFileName As String)

    To get this project to be automatically loaded and run when you start MicroStation, perform the following:

      • From within a design file, select Utilities > Macro > Project Manager
      • In the resulting Project Manager dialog, select Load Project button.
      • Check the Auto-Load column on the right side of the project entry.

    • Close and restart MicroStation.



    The results of this little macro will be evident immediately and will run on every file you open or close.

    Due to the powerful nature of this program, read and take heed to all warnings as outlined in the code. It is strongly advised that you thoroughly test this application before deploying it in production.

     

    This program is supplied as is. Geospatial Paradigm Solutions, Inc. disclaims all warranties, express or implied, including, without limitation, the warranties of merchantability and of fitness of this program for any purpose. Geospatial Paradigm Solutions, Inc. assumes no liability for damages direct, indirect, or consequential, which may result from the use of this program. Geospatial Paradigm Solutions, Inc. does not warrant this program. Use this program at your own risk.

    AskInga Article #174

    • Askinga
    • Automation
    • Programming
    • FreewareShareware
    • Article
    • Share
    • History
    • More
    • Cancel
    • Anonymous Created by Anonymous
    • When: Thu, May 29 2008 9:59 AM
    • David Trejo-Rodriguez Last revision by Bentley Colleague David Trejo-Rodriguez
    • When: Sat, Dec 31 2022 5:27 PM
    • Revisions: 10
    • Comments: 2
    Recommended
    Related
    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies