Hi,
I have got a macro in an mvba file, and set it to autoload.
How can I get it to be that every time I open a file with MicroStation, this macro executes straight away.
I have used the help page below but am not able to understand any of it. Could someone provide some clear step by step instructions. I have no programming background.
http://communities.bentley.com/communities/other_communities/askinga/w/askinga/run-commands-or-basic-macro-when-opening-files
Thanks in advance
I have got a macro in an mvba file, and set it to autoload
That loads a VBA macro into memory, but does not run it (but it's the right thing to do).
How can I get it to be that every time I open a file with MicroStation, this macro executes
Write a class that handles MicroStation DGN events. Search VBA help for Working with MicroStation events. Write a class that handles WithEvents as described, and put the code to start your macro into sub hooks_OnDesignFileOpened. Here's an article about that same topic.
Regards, Jon Summers LA Solutions
There should be at least two modules in your VBA project:
The normal module has a global variablePrivate m_oOpenClose As clsOpenClose
And a public procedure:
Sub Main () Set m_oOpenClose = New clsOpenClose End Sub
Your class contains this essential declaration: Private WithEvents hooks As Application And the procedures that are show in our web page. When you load your project, MicroStation sees the public procedure OnProjectLoad. It executes that procedure, which starts your event handler class. You won't see anything happen until you close your DGN and open another DGN.
Unknown said:The macro it loads only when I click file and then open. It does not open if I go to windows explorer and then double click the file to open
This could be a MicroStation workspace issue.
When you 'click the file and then open', have you already started MicroStation with a specific workspace? That is, are you using the workspace where you have defined configuration variable MS_VBAAUTOLOADPROJECTS?
When you double-click a DGN file in Windows Explorer, you start MicroStation using its default workspace. If your configuration variables are not defined in a default workspace, then your VBA project is not loaded.
Attached is a program called "runVBA.ma" and the readme file that explains how to use it.
I have had great success with this old program. We put it in our Site config file as follows....
# List of MDL applications to load automatically when a DGN file is opened
MS_DGNAPPS > runVBA.ma
# assigns the names of macros to run each time a design file is opened
MS_DGNMACROS > mymacro.bahttps://communities.bentley.com/cfs-file/__key/communityserver-discussions-components-files/343173/runVBA.marunVBAREADME.TXT
Jon I tried the link, it failed I tried to message it failed
If possible I really wanted to attempt getting something like this
going. I also need the Fit View and a few key-in when opening each file. I currently have a script which runs the VBA and the key-in commands, I also have to set some settings in View Attributes. This looks or reads like it could really help. I found the one on Basic but I have stayed away from it due to earlier counsel from you or Ron because you can do so much more in VBA. I hope you see this message.
You always seem to be a kind and great help. Thank you
Version: MicroStation V8i SS 10
RJB Phillips III (Richard) Praise the Lord for His Mercy and grace in Christ Jesus
Richard Phillips said:I tried the link, it failed
Thanks for pointing that out: I've fixed the link.