<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Running VBA after Open menu item in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273818#M19533</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Why not call the vba program from the AcadDoc.lsp file?&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Regards&lt;BR /&gt;
&lt;BR /&gt;
Laurie&lt;BR /&gt;
&lt;BR /&gt;
arcticad wrote:&lt;BR /&gt;
&amp;gt; Store a value in the drawing and have your code check for that value. &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Then it will only run once.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I'm not sure about the opening problem. But this works for me.</description>
    <pubDate>Mon, 09 Jun 2008 22:16:21 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2008-06-09T22:16:21Z</dc:date>
    <item>
      <title>Running VBA after Open menu item</title>
      <link>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273812#M19527</link>
      <description>I'm trying to run a VBA program every time the Open command is issued from the pull-down menu.  I'm using the following macro in the menu:&lt;BR /&gt;
^C^C_open;-vbarun;N:/ACAD/KEN/VBA-Testing/Notification2.dvb!Module1.Notification;lwdefault;0;&lt;BR /&gt;
&lt;BR /&gt;
The program opens a file, as normal, but then doesn't do the rest of the macro (i.e. open the the vba program and run it).  Then when I close the file, the macro continues to run (i.e. opens the vba program, runs it, and changes the lineweight default).&lt;BR /&gt;
&lt;BR /&gt;
So it looks like the there is something with the OPEN command that doesn't finish until the drawing is closed.  Yet, I can edit the file and go on to other commands.  It's just the macro won't finish until the file is closed.&lt;BR /&gt;
&lt;BR /&gt;
Any insight to this issue would be helpful.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Ken</description>
      <pubDate>Mon, 09 Jun 2008 15:11:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273812#M19527</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-06-09T15:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: Running VBA after Open menu item</title>
      <link>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273813#M19528</link>
      <description>You can't run VBA code while a modal Dialog Box is displayed. &lt;BR /&gt;
&lt;BR /&gt;
Your code will wait untill the dialog is closed.</description>
      <pubDate>Mon, 09 Jun 2008 15:53:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273813#M19528</guid>
      <dc:creator>arcticad</dc:creator>
      <dc:date>2008-06-09T15:53:25Z</dc:date>
    </item>
    <item>
      <title>Re: Running VBA after Open menu item</title>
      <link>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273814#M19529</link>
      <description>Thanks for the reply.  Here's the sequence that is happening:&lt;BR /&gt;
1. select Open from the menu&lt;BR /&gt;
2. dialog box opens&lt;BR /&gt;
3. select drawing&lt;BR /&gt;
4. dialog box closes&lt;BR /&gt;
5. drawing opens&lt;BR /&gt;
6. Then I can do normal editing, but the rest of the macro hasn't run yet.&lt;BR /&gt;
7. I close drawing&lt;BR /&gt;
8. macro continues wtih VBA load and lwdefault change&lt;BR /&gt;
&lt;BR /&gt;
So the dialog box is closing, but he code doesn't continue until the drawing is closed.&lt;BR /&gt;
&lt;BR /&gt;
I think I may have found another way to do this, using the EndOpen event.  I'm experimenting with it now.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Ken</description>
      <pubDate>Mon, 09 Jun 2008 16:05:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273814#M19529</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-06-09T16:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: Running VBA after Open menu item</title>
      <link>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273815#M19530</link>
      <description>This is how I would handle this. &lt;BR /&gt;
&lt;BR /&gt;
I would use the AcadDocument_Activate() event to have it run the code. &lt;BR /&gt;
&lt;BR /&gt;
If you only want the code to once per the drawing being opened: &lt;BR /&gt;
&lt;BR /&gt;
1. Open Drawing.&lt;BR /&gt;
2. Drawing Activates. &lt;BR /&gt;
3. Run Your Code. &lt;BR /&gt;
4. Store Custom Dictionary Entry in the drawing. &lt;BR /&gt;
(Use this to check if the program has already run during this session)&lt;BR /&gt;
&lt;BR /&gt;
Add a check on AcadDocument_BeginSave(ByVal FileName As String) to remove the Dictionary entry when saving.</description>
      <pubDate>Mon, 09 Jun 2008 16:58:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273815#M19530</guid>
      <dc:creator>arcticad</dc:creator>
      <dc:date>2008-06-09T16:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: Running VBA after Open menu item</title>
      <link>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273816#M19531</link>
      <description>That's a possibility, but I only want this to run once when the drawing is open.  The Activate event would trigger whenever the drawing window is highlighted (i.e. whenever you switch between drawings).&lt;BR /&gt;
&lt;BR /&gt;
I'm still trying to figure out why the Open menu command won't run this immediately after opening a drawing.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Ken</description>
      <pubDate>Mon, 09 Jun 2008 17:26:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273816#M19531</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-06-09T17:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: Running VBA after Open menu item</title>
      <link>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273817#M19532</link>
      <description>Store a value in the drawing and have your code check for that value. &lt;BR /&gt;
&lt;BR /&gt;
Then it will only run once.&lt;BR /&gt;
&lt;BR /&gt;
I'm not sure about the opening problem. But this works for me.</description>
      <pubDate>Mon, 09 Jun 2008 18:18:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273817#M19532</guid>
      <dc:creator>arcticad</dc:creator>
      <dc:date>2008-06-09T18:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Running VBA after Open menu item</title>
      <link>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273818#M19533</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Why not call the vba program from the AcadDoc.lsp file?&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Regards&lt;BR /&gt;
&lt;BR /&gt;
Laurie&lt;BR /&gt;
&lt;BR /&gt;
arcticad wrote:&lt;BR /&gt;
&amp;gt; Store a value in the drawing and have your code check for that value. &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Then it will only run once.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I'm not sure about the opening problem. But this works for me.</description>
      <pubDate>Mon, 09 Jun 2008 22:16:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273818#M19533</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-06-09T22:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: Running VBA after Open menu item</title>
      <link>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273819#M19534</link>
      <description>Laurie,&lt;BR /&gt;
thanks for the info.  There's a couple reasons, but I may still look at it.&lt;BR /&gt;
1. I haven't done much programming in AutoLisp, and so wasn't aware of that routine/file.&lt;BR /&gt;
&lt;BR /&gt;
2. I was trying to find a simple way to distribute to end-users.  My end-users use the same menu, and adding to the Open command seemed the simplest method.&lt;BR /&gt;
&lt;BR /&gt;
3. We run batch processing (vba programs), for which I don't want this program to run on (the program sends an email notifcation to a distribution list when a drawing is manually opened for editing - due to running on two servers).  The batch files would bypass the menu OPEN command, but would be affected by anything that is set to globally intercept and OPEN event.&lt;BR /&gt;
&lt;BR /&gt;
I did get the EndOpen event to work (triggering it with the acad2009.lsp file), but I ran into the issue described in #3 (above) when I run batch files (i.e. the program running when I don't want it to).&lt;BR /&gt;
&lt;BR /&gt;
So I may try using the acaddoc.lsp file.  Do you know what the code in that file would need to be?&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Ken</description>
      <pubDate>Mon, 09 Jun 2008 22:37:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273819#M19534</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-06-09T22:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: Running VBA after Open menu item</title>
      <link>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273820#M19535</link>
      <description>There is a very good reason to avoid Calling VBA from a lisp file. &lt;BR /&gt;
Especially on Startup. &lt;BR /&gt;
&lt;BR /&gt;
Lisp code can not run as the same time as VBA. &lt;BR /&gt;
&lt;BR /&gt;
The Lisp routine will call the VBA function and then try to continue on. &lt;BR /&gt;
&lt;BR /&gt;
The Lisp file will not wait untill the VBA is finished. &lt;BR /&gt;
&lt;BR /&gt;
The Result, Autocad Will Stop. You won't be able to Esc out of it.&lt;BR /&gt;
&lt;BR /&gt;
If you want to have your code load only when Autocad is Visible: Not BatchPlotting in the background then you can check if Autocad is on the screen.&lt;BR /&gt;
&lt;BR /&gt;
Add this to a .lsp file. it doesn't matter what the name is. And Add it to your startup Suite. &lt;BR /&gt;
&lt;BR /&gt;
[code]&lt;BR /&gt;
&lt;BR /&gt;
(DEFUN startup_errortrap (errmsg) (PRINC (STRCAT "\n" errmsg)) (SETQ *error* temperr) (PRINC))&lt;BR /&gt;
&lt;BR /&gt;
(DEFUN s::startup ()&lt;BR /&gt;
  (VL-LOAD-COM)&lt;BR /&gt;
  (SETQ temperr *error*)&lt;BR /&gt;
  (SETQ *error* startup_errortrap)&lt;BR /&gt;
  (IF (= (VLAX-GET-PROPERTY (VLAX-GET-ACAD-OBJECT) "Visible") :VLAX-TRUE)&lt;BR /&gt;
    (PROGN (VL-VBALOAD "c:\myprogram\program1.dvb"))&lt;BR /&gt;
  )&lt;BR /&gt;
)&lt;BR /&gt;
&lt;BR /&gt;
[/code]</description>
      <pubDate>Mon, 09 Jun 2008 22:57:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273820#M19535</guid>
      <dc:creator>arcticad</dc:creator>
      <dc:date>2008-06-09T22:57:37Z</dc:date>
    </item>
    <item>
      <title>Re: Running VBA after Open menu item</title>
      <link>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273821#M19536</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
The simplest code to run a VBA program from lisp is:&lt;BR /&gt;
&lt;BR /&gt;
(VL-LOAD-COM)&lt;BR /&gt;
(VBA-RUN "C:\\MyprogramPath\\MyProgramName.dvb!MyMacroName")&lt;BR /&gt;
&lt;BR /&gt;
Or you could place it in a function and then run the function like this:&lt;BR /&gt;
&lt;BR /&gt;
(defun fred ()&lt;BR /&gt;
   (VL-LOAD-COM)&lt;BR /&gt;
   (VBA-RUN "C:\\MyprogramPath\\MyProgramName.dvb!MyMacroName")&lt;BR /&gt;
)&lt;BR /&gt;
(fred}&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
You can make this the last entry in the Lisp file so that no extra lisp &lt;BR /&gt;
is needed to run afterwards to obviate the problems implied by arcticad.&lt;BR /&gt;
&lt;BR /&gt;
Personally I haven't experienced those problems.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Regards&lt;BR /&gt;
&lt;BR /&gt;
Laurie&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
KWashburn wrote:&lt;BR /&gt;
&amp;gt; Laurie,&lt;BR /&gt;
&amp;gt; thanks for the info.  There's a couple reasons, but I may still look at it.&lt;BR /&gt;
&amp;gt; 1. I haven't done much programming in AutoLisp, and so wasn't aware of that routine/file.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; 2. I was trying to find a simple way to distribute to end-users.  My end-users use the same menu, and adding to the Open command seemed the simplest method.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; 3. We run batch processing (vba programs), for which I don't want this program to run on (the program sends an email notifcation to a distribution list when a drawing is manually opened for editing - due to running on two servers).  The batch files would bypass the menu OPEN command, but would be affected by anything that is set to globally intercept and OPEN event.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I did get the EndOpen event to work (triggering it with the acad2009.lsp file), but I ran into the issue described in #3 (above) when I run batch files (i.e. the program running when I don't want it to).&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; So I may try using the acaddoc.lsp file.  Do you know what the code in that file would need to be?&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Thanks,&lt;BR /&gt;
&amp;gt; Ken</description>
      <pubDate>Tue, 10 Jun 2008 04:31:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273821#M19536</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-06-10T04:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: Running VBA after Open menu item</title>
      <link>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273822#M19537</link>
      <description>Thanks arcticad and Laurie for the valuable information.  I'll give it a try.&lt;BR /&gt;
&lt;BR /&gt;
Ken</description>
      <pubDate>Tue, 10 Jun 2008 13:34:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/running-vba-after-open-menu-item/m-p/2273822#M19537</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-06-10T13:34:07Z</dc:date>
    </item>
  </channel>
</rss>

