Macro won't run if...

Programming and macros
User avatar
loeb
Posts: 68
Joined: Sun Jan 16, 2022 5:55 pm
Answers: 1
x 39
x 10

Macro won't run if...

Unread post by loeb »

If I run a macro while a cell in a drawing table is selected, nothing happens on the first click. If I click on the run icon a second time, it works fine.

This bahavior happens when running a macro using a "new macro button" in the SW UI or when hitting the "run sub" play button in VB for Applications. If I run a macro using a "Run Macro" button in the SW UI or from Tools/Add-Ins/Macros/Run, it works fine.

Here's the code:

Code: Select all

Option Explicit
Sub main()
    Debug.Print "HELLO WORLD"
End Sub
Of course, that's not my real code, the point is, it doesn't matter what macro I try to run, the behavior is the same.

I experience this behavior if I have cell, row, column, or range in a table selected. If I instead select the entire table, it works fine.

It doesn't matter what kind of table (General, Revision, BOM, etc).

Since the solution is to simply click on my macro-run button a second time, it's not the end of the world, but it is creating a lot of confusion among other SW users since this behavior is unexpected and unexplainable.

I have experienced this behavior in both 2017 SP 5.0 and 2022 SP 5.0
User avatar
gupta9665
Posts: 411
Joined: Thu Mar 11, 2021 10:20 am
Answers: 25
Location: India
x 434
x 450

Re: Macro won't run if...

Unread post by gupta9665 »

I have not seen this behavior earlier, so will it be possible for you to share your screen and show the issue?
Deepak Gupta
SOLIDWORKS Consultant/Blogger
User avatar
AlexLachance
Posts: 2187
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2373
x 2015

Re: Macro won't run if...

Unread post by AlexLachance »

Do you happen to have hidden messages..? Perhaps that is a trigger for the issue..?
User avatar
AlexB
Posts: 501
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 269
x 445

Re: Macro won't run if...

Unread post by AlexB »

I'm only able to sort of duplicate this. If I select a cell and then move to click the "play" button on the macro editor, it doesn't do anything. However I don't believe this is necessarily an issue with the macro execution and more the way focus is handled.

If I select the cell, then click the header of the macro editor to focus back to that then click the "play" button, everything runs fine. It seems that there's a bit of a hiccup when the focus is moving back to the editor by executing a macro after selecting a cell. Strange indeed.
User avatar
loeb
Posts: 68
Joined: Sun Jan 16, 2022 5:55 pm
Answers: 1
x 39
x 10

Re: Macro won't run if...

Unread post by loeb »

I'll share some videos soon, but in the meantime, I discovered that the behavior is different, depending on where the "new macro" button has been placed. If I put it on the Macro Toolbar, they seem to work on the first click. If I put the "new macro" button on the SW Window Title Bar or in the Command Manager Macro tab, I get different behavior. More to come...
User avatar
loeb
Posts: 68
Joined: Sun Jan 16, 2022 5:55 pm
Answers: 1
x 39
x 10

Re: Macro won't run if...

Unread post by loeb »

I have figured out a lot about this issue. It's really not a macro/API issue at all because it affects other command buttons as well. Here we go.
image.png
There are 3 placed in the SW that I tried placing "new macro" buttons for various macros that I use. I also put a "measuring tool" button in each of those places to test non-macro behavior. Here are the 3 places I put the buttons:

1) At the top of the SW UI, in the Title Bar.
2) In the Macro tab of the Command Manager.
3) In the Macro Toolbar.[/list]

I tested buttons from each location after selecting a cell in the table. Before each test, I selected the background before selecting a cell again.

1) I found that for any button in 1) above (title bar), the first time I pressed it, nothing happens. Then, on the second or subsequent presses, it works great. The measuring tool button behaves the same way.

2) For case 2) above (command manager), I was able to sometimes recreate the behavior of 1), but at other times it works fine.

3) For case 3) above (macro toolbar), all the buttons always work.

So it seems to have something to do with the SW UI in general and doesn't have anything to do with macros or the API per se. I'll stop putting my macro button on the title bar and instead use the macro toolbar (or command manager maybe?).
Post Reply