Discussion:
How to start a macro i Default.ivb from VB
(too old to reply)
Lasse Frederiksen
2005-02-17 15:36:38 UTC
Permalink
Simple question... How do I do that... I would like to pass a parameter too,
if its possible

Lasse
Sam Bixler
2005-02-18 12:03:24 UTC
Permalink
Kent Keller answered this question for me in a thread entitled "default VBA
project isn't loaded -- IV9 SP1" dated 10/15/04. But you won't be able to
pass a parameter directly to a macro. Macros, by definition, have no
arguments. There's probably some way around that limitation, but I don't
know what it would be. In my case, my one parameter could have three
different values, so I simply made three different macros which do nothing
but call the main procedure with one of those values as an argument.

Hope this is useful.
--
Sam Bixler
Eli Lilly and Company, Indianapolis
Post by Lasse Frederiksen
Simple question... How do I do that... I would like to pass a parameter too,
if its possible
Lasse
Kevin Wehner (IV9 SP2)
2005-02-18 14:55:21 UTC
Permalink
I'm just getting back into VB after several years. But if I remember
correctly, you define a function and then take your macro codes and place it
in the function.
Post by Sam Bixler
Kent Keller answered this question for me in a thread entitled "default VBA
project isn't loaded -- IV9 SP1" dated 10/15/04. But you won't be able to
pass a parameter directly to a macro. Macros, by definition, have no
arguments. There's probably some way around that limitation, but I don't
know what it would be. In my case, my one parameter could have three
different values, so I simply made three different macros which do nothing
but call the main procedure with one of those values as an argument.
Hope this is useful.
--
Sam Bixler
Eli Lilly and Company, Indianapolis
Post by Lasse Frederiksen
Simple question... How do I do that... I would like to pass a parameter
too,
Post by Lasse Frederiksen
if its possible
Lasse
Lasse Frederiksen
2005-02-21 12:30:27 UTC
Permalink
Kent answer didn't run a specific macro, it only loaded the default.ivb...

The macro in default.ivb i'm trying to run is named

Public Sub PMNAutoSaveBefore(oName as String)

The way i'm doing it now is like this:

Private Sub oRunAutoMacro()
Dim oVBA As InventorVBAProjects
Set oVBA = oApp.VBAProjects
Dim oVBAProject As InventorVBAProject
Dim oVBAComponent As InventorVBAComponent
Dim oVBAMember As InventorVBAMember
For Each oVBAProject In oVBA
If oVBAProject.Name = "ApplicationProject" Then
For Each oVBAComponent In oVBAProject.InventorVBAComponents
If oVBAComponent.Name = "AutoMacros" Then
For Each oVBAMember In oVBAComponent.InventorVBAMembers
If oVBAMember.Name = "PMNAutoSaveBefore" Then
oVBAMember.Execute
Exit For
End If
Next
Exit For
End If
Next
Exit For
End If
Next
End Sub

I would just like a direct way to run this macro, and maby a way to pass the
oName to the macro..


Lasse
Post by Sam Bixler
Kent Keller answered this question for me in a thread entitled "default VBA
project isn't loaded -- IV9 SP1" dated 10/15/04. But you won't be able to
pass a parameter directly to a macro. Macros, by definition, have no
arguments. There's probably some way around that limitation, but I don't
know what it would be. In my case, my one parameter could have three
different values, so I simply made three different macros which do nothing
but call the main procedure with one of those values as an argument.
Hope this is useful.
--
Sam Bixler
Eli Lilly and Company, Indianapolis
Post by Lasse Frederiksen
Simple question... How do I do that... I would like to pass a parameter
too,
Post by Lasse Frederiksen
if its possible
Lasse
Sam Bixler
2005-02-22 13:26:50 UTC
Permalink
Sorry, Lasse, I am not an expert programmer. But I think, from reading the
help files, that a procedure is not a macro unless it has no arguments. So
there is no way to pass parameters directly to a macro. There might be a
workaround or some other way to get the job done indirectly. Or maybe there
is a way to run a non-macro procedure (one that has arguments). Your code
looks as if it should work, but only if PMNAutoSaveBefore() would be a
macro. I'm guessing that PMNAutoSaveBefore doesn't run when you execute
your code, and that would be because it isn't part of the VBAMembers
collection. If, in Inventor, you go to Tools > Macro > Macros, it will show
the members of that collection, and you will know for sure. But I don't
have any ideas for workarounds.
--
Sam Bixler
Eli Lilly and Company, Indianapolis
Post by Lasse Frederiksen
Kent answer didn't run a specific macro, it only loaded the default.ivb...
The macro in default.ivb i'm trying to run is named
Public Sub PMNAutoSaveBefore(oName as String)
Private Sub oRunAutoMacro()
Dim oVBA As InventorVBAProjects
Set oVBA = oApp.VBAProjects
Dim oVBAProject As InventorVBAProject
Dim oVBAComponent As InventorVBAComponent
Dim oVBAMember As InventorVBAMember
For Each oVBAProject In oVBA
If oVBAProject.Name = "ApplicationProject" Then
For Each oVBAComponent In oVBAProject.InventorVBAComponents
If oVBAComponent.Name = "AutoMacros" Then
For Each oVBAMember In
oVBAComponent.InventorVBAMembers
Post by Lasse Frederiksen
If oVBAMember.Name = "PMNAutoSaveBefore" Then
oVBAMember.Execute
Exit For
End If
Next
Exit For
End If
Next
Exit For
End If
Next
End Sub
I would just like a direct way to run this macro, and maby a way to pass the
oName to the macro..
Lasse
Post by Sam Bixler
Kent Keller answered this question for me in a thread entitled "default VBA
project isn't loaded -- IV9 SP1" dated 10/15/04. But you won't be able to
pass a parameter directly to a macro. Macros, by definition, have no
arguments. There's probably some way around that limitation, but I don't
know what it would be. In my case, my one parameter could have three
different values, so I simply made three different macros which do nothing
but call the main procedure with one of those values as an argument.
Hope this is useful.
--
Sam Bixler
Eli Lilly and Company, Indianapolis
Post by Lasse Frederiksen
Simple question... How do I do that... I would like to pass a parameter
too,
Post by Lasse Frederiksen
if its possible
Lasse
Lasse Frederiksen
2005-02-23 09:31:58 UTC
Permalink
It is working, but the problem is that it searches instead of going directly
to the macro, and that takes time, when doing it to a 1000+ assembly

Thanks for the input anyway
Post by Sam Bixler
Sorry, Lasse, I am not an expert programmer. But I think, from reading the
help files, that a procedure is not a macro unless it has no arguments.
So
there is no way to pass parameters directly to a macro. There might be a
workaround or some other way to get the job done indirectly. Or maybe there
is a way to run a non-macro procedure (one that has arguments). Your code
looks as if it should work, but only if PMNAutoSaveBefore() would be a
macro. I'm guessing that PMNAutoSaveBefore doesn't run when you execute
your code, and that would be because it isn't part of the VBAMembers
collection. If, in Inventor, you go to Tools > Macro > Macros, it will show
the members of that collection, and you will know for sure. But I don't
have any ideas for workarounds.
--
Sam Bixler
Eli Lilly and Company, Indianapolis
Post by Lasse Frederiksen
Kent answer didn't run a specific macro, it only loaded the
default.ivb...
The macro in default.ivb i'm trying to run is named
Public Sub PMNAutoSaveBefore(oName as String)
Private Sub oRunAutoMacro()
Dim oVBA As InventorVBAProjects
Set oVBA = oApp.VBAProjects
Dim oVBAProject As InventorVBAProject
Dim oVBAComponent As InventorVBAComponent
Dim oVBAMember As InventorVBAMember
For Each oVBAProject In oVBA
If oVBAProject.Name = "ApplicationProject" Then
For Each oVBAComponent In oVBAProject.InventorVBAComponents
If oVBAComponent.Name = "AutoMacros" Then
For Each oVBAMember In
oVBAComponent.InventorVBAMembers
Post by Lasse Frederiksen
If oVBAMember.Name = "PMNAutoSaveBefore" Then
oVBAMember.Execute
Exit For
End If
Next
Exit For
End If
Next
Exit For
End If
Next
End Sub
I would just like a direct way to run this macro, and maby a way to pass
the
Post by Lasse Frederiksen
oName to the macro..
Lasse
Post by Sam Bixler
Kent Keller answered this question for me in a thread entitled "default VBA
project isn't loaded -- IV9 SP1" dated 10/15/04. But you won't be able
to
Post by Lasse Frederiksen
Post by Sam Bixler
pass a parameter directly to a macro. Macros, by definition, have no
arguments. There's probably some way around that limitation, but I
don't
Post by Lasse Frederiksen
Post by Sam Bixler
know what it would be. In my case, my one parameter could have three
different values, so I simply made three different macros which do
nothing
Post by Lasse Frederiksen
Post by Sam Bixler
but call the main procedure with one of those values as an argument.
Hope this is useful.
--
Sam Bixler
Eli Lilly and Company, Indianapolis
Post by Lasse Frederiksen
Simple question... How do I do that... I would like to pass a parameter
too,
Post by Lasse Frederiksen
if its possible
Lasse
Scott Stubbington
2005-02-23 16:02:33 UTC
Permalink
Hello,
What's passed to the macro, i.e. what values would passed in oName? Name of
a file, a part you're currently editing in an assembly, etc. How is it not
possible to do this from VB, why not re-write the sub in VB and utilize the
output from within VB alone?
Is strikes me that you're executing the macro without passing any values to
it here 'oVBAMember.Execute', hence why do you need to search for it, why
not just execute the macro?
.... maybe I'm missing the point :-)

Scott
Post by Lasse Frederiksen
It is working, but the problem is that it searches instead of going
directly to the macro, and that takes time, when doing it to a 1000+
assembly
Thanks for the input anyway
Post by Sam Bixler
Sorry, Lasse, I am not an expert programmer. But I think, from reading the
help files, that a procedure is not a macro unless it has no arguments.
So
there is no way to pass parameters directly to a macro. There might be a
workaround or some other way to get the job done indirectly. Or maybe there
is a way to run a non-macro procedure (one that has arguments). Your code
looks as if it should work, but only if PMNAutoSaveBefore() would be a
macro. I'm guessing that PMNAutoSaveBefore doesn't run when you execute
your code, and that would be because it isn't part of the VBAMembers
collection. If, in Inventor, you go to Tools > Macro > Macros, it will show
the members of that collection, and you will know for sure. But I don't
have any ideas for workarounds.
--
Sam Bixler
Eli Lilly and Company, Indianapolis
Post by Lasse Frederiksen
Kent answer didn't run a specific macro, it only loaded the
default.ivb...
The macro in default.ivb i'm trying to run is named
Public Sub PMNAutoSaveBefore(oName as String)
Private Sub oRunAutoMacro()
Dim oVBA As InventorVBAProjects
Set oVBA = oApp.VBAProjects
Dim oVBAProject As InventorVBAProject
Dim oVBAComponent As InventorVBAComponent
Dim oVBAMember As InventorVBAMember
For Each oVBAProject In oVBA
If oVBAProject.Name = "ApplicationProject" Then
For Each oVBAComponent In oVBAProject.InventorVBAComponents
If oVBAComponent.Name = "AutoMacros" Then
For Each oVBAMember In
oVBAComponent.InventorVBAMembers
Post by Lasse Frederiksen
If oVBAMember.Name = "PMNAutoSaveBefore" Then
oVBAMember.Execute
Exit For
End If
Next
Exit For
End If
Next
Exit For
End If
Next
End Sub
I would just like a direct way to run this macro, and maby a way to pass
the
Post by Lasse Frederiksen
oName to the macro..
Lasse
Post by Sam Bixler
Kent Keller answered this question for me in a thread entitled
"default
VBA
project isn't loaded -- IV9 SP1" dated 10/15/04. But you won't be able
to
Post by Lasse Frederiksen
Post by Sam Bixler
pass a parameter directly to a macro. Macros, by definition, have no
arguments. There's probably some way around that limitation, but I
don't
Post by Lasse Frederiksen
Post by Sam Bixler
know what it would be. In my case, my one parameter could have three
different values, so I simply made three different macros which do
nothing
Post by Lasse Frederiksen
Post by Sam Bixler
but call the main procedure with one of those values as an argument.
Hope this is useful.
--
Sam Bixler
Eli Lilly and Company, Indianapolis
Post by Lasse Frederiksen
Simple question... How do I do that... I would like to pass a parameter
too,
Post by Lasse Frederiksen
if its possible
Lasse
Lasse Frederiksen
2005-02-25 08:38:07 UTC
Permalink
Your not missing the point, the point is, how do i just execute the macro,
whitout searching for it....

It a addin, that runs on every save (this works), I would like to pass the
filename to my macro (not nessesary, but it would be nice)... I'm doing it
like this because i think it is kind of difficult to edit an add in. I'm not
that good in VB yet, so my macros have a lot of errors in the beginning, and
I still come up with new ideas, that needs to be added. The basic idea is to
call a macro in default VB, that does what i want, i think it is much easyer
to find errors in VBA that in VB.

Lasse
Post by Scott Stubbington
Hello,
What's passed to the macro, i.e. what values would passed in oName? Name
of a file, a part you're currently editing in an assembly, etc. How is it
not possible to do this from VB, why not re-write the sub in VB and
utilize the output from within VB alone?
Is strikes me that you're executing the macro without passing any values
to it here 'oVBAMember.Execute', hence why do you need to search for it,
why not just execute the macro?
.... maybe I'm missing the point :-)
Scott
Post by Lasse Frederiksen
It is working, but the problem is that it searches instead of going
directly to the macro, and that takes time, when doing it to a 1000+
assembly
Thanks for the input anyway
Post by Sam Bixler
Sorry, Lasse, I am not an expert programmer. But I think, from reading the
help files, that a procedure is not a macro unless it has no arguments.
So
there is no way to pass parameters directly to a macro. There might be a
workaround or some other way to get the job done indirectly. Or maybe there
is a way to run a non-macro procedure (one that has arguments). Your code
looks as if it should work, but only if PMNAutoSaveBefore() would be a
macro. I'm guessing that PMNAutoSaveBefore doesn't run when you execute
your code, and that would be because it isn't part of the VBAMembers
collection. If, in Inventor, you go to Tools > Macro > Macros, it will show
the members of that collection, and you will know for sure. But I don't
have any ideas for workarounds.
--
Sam Bixler
Eli Lilly and Company, Indianapolis
Post by Lasse Frederiksen
Kent answer didn't run a specific macro, it only loaded the
default.ivb...
The macro in default.ivb i'm trying to run is named
Public Sub PMNAutoSaveBefore(oName as String)
Private Sub oRunAutoMacro()
Dim oVBA As InventorVBAProjects
Set oVBA = oApp.VBAProjects
Dim oVBAProject As InventorVBAProject
Dim oVBAComponent As InventorVBAComponent
Dim oVBAMember As InventorVBAMember
For Each oVBAProject In oVBA
If oVBAProject.Name = "ApplicationProject" Then
For Each oVBAComponent In oVBAProject.InventorVBAComponents
If oVBAComponent.Name = "AutoMacros" Then
For Each oVBAMember In
oVBAComponent.InventorVBAMembers
Post by Lasse Frederiksen
If oVBAMember.Name = "PMNAutoSaveBefore" Then
oVBAMember.Execute
Exit For
End If
Next
Exit For
End If
Next
Exit For
End If
Next
End Sub
I would just like a direct way to run this macro, and maby a way to pass
the
Post by Lasse Frederiksen
oName to the macro..
Lasse
Post by Sam Bixler
Kent Keller answered this question for me in a thread entitled
"default
VBA
project isn't loaded -- IV9 SP1" dated 10/15/04. But you won't be able
to
Post by Lasse Frederiksen
Post by Sam Bixler
pass a parameter directly to a macro. Macros, by definition, have no
arguments. There's probably some way around that limitation, but I
don't
Post by Lasse Frederiksen
Post by Sam Bixler
know what it would be. In my case, my one parameter could have three
different values, so I simply made three different macros which do
nothing
Post by Lasse Frederiksen
Post by Sam Bixler
but call the main procedure with one of those values as an argument.
Hope this is useful.
--
Sam Bixler
Eli Lilly and Company, Indianapolis
Post by Lasse Frederiksen
Simple question... How do I do that... I would like to pass a parameter
too,
Post by Lasse Frederiksen
if its possible
Lasse
Loading...