VBA launch via menu button

VBA launch via menu button

Anonymous
Not applicable
1,402 Views
18 Replies
Message 1 of 19

VBA launch via menu button

Anonymous
Not applicable
Can anyone tell me why I would get the command line error, "Macro not found" when I run the following macro in a button;
^C^C-vbarun "V:/VBA/excel_launch.dvb"

The macro "excel_launch.dvb" is in the correct directory, so I am at a loss.
0 Likes
1,403 Views
18 Replies
Replies (18)
Message 2 of 19

Anonymous
Not applicable
You are trying to run a DVB not a macro. Have a look in the help file for the correct useage of vbaload & vbarun.

Regards - Nathan
0 Likes
Message 3 of 19

Anonymous
Not applicable
Hi,

You are only calling your program, not its internal macro. You need to
nominate that as well.

^C^C-vbarun "V:/VBA/excel_launch.dvb!MyMacro"

Search back through this NG, there are dozens of posts on this subject.

--
Regards


Laurie Comerford
www.cadapps.com.au
wrote in message news:[email protected]...
Can anyone tell me why I would get the command line error, "Macro not found"
when I run the following macro in a button;
^C^C-vbarun "V:/VBA/excel_launch.dvb"

The macro "excel_launch.dvb" is in the correct directory, so I am at a loss.
0 Likes
Message 4 of 19

Anonymous
Not applicable
My apologies. I have searched on "VBA launch button" and "VBA custom button" and "VBA from menu button" and I have narrowed it down to this;
^C^C^P(vl-vbarun "c://myfolder//myproject.dvb!mymodule.mymacro")

My problem is, I don't know what should be in the place of "mymodule.mymacro"
This is where my confusion is coming from.
Forgive me; I am new to VBA. Message was edited by: TR Young
0 Likes
Message 5 of 19

Anonymous
Not applicable
"mymodule.mymacro"
What is the name of the module that contains the macro you want to run?
What is the name of the macro?

i.e. this would be called as [module1.stub]

Sub stub()
...
End Sub


wrote in message news:[email protected]...
My apologies. I have searched on "VBA launch button" and "VBA custom
button" and "VBA from menu button" and I have narrowed it down to this;
^C^C^P(vl-vbarun "c://myfolder//myproject.dvb!mymodule.mymacro")

My problem is, I don't know what should be in the place of
"mymodule.mymacro"
This is where my confusion is coming from.
Forgive me; I am new to VBA.

Message was edited by: TR Young
0 Likes
Message 6 of 19

Anonymous
Not applicable
I do not understand that at all.

Sub stub()
...
End sub

can't go in a button macro.
0 Likes
Message 7 of 19

Anonymous
Not applicable
Not if you don't know it's name, nor are willing
to learn anything about what you're asking.

wrote in message news:[email protected]...
I do not understand that at all.

Sub stub()
...
End sub

can't go in a button macro.
0 Likes
Message 8 of 19

Anonymous
Not applicable
Now I'm really lost. What are you trying to say here?
0 Likes
Message 9 of 19

Anonymous
Not applicable
This is not a macro it's a container for your modules which
are containers for your macros. Figure those out and you'll
have your answer. Open the dvb and find the name of
the macro you want to call, and the name of the module
it's contained in.

wrote in message news:[email protected]...
Now I'm really lost. What are you trying to say here?
0 Likes
Message 10 of 19

Anonymous
Not applicable
Enter "Learning VBA" into a google search box.
There' s more to using VBA macro than just entering a file/folder path in
the command line.
First don't confuse a menu macro with a VBA macro.
Second you need to know how a vba project is structured to get the sub
routine's (macro) name and what arguments need to be passed to it .


Murph
--
http://mappingitout.blogspot.com/
wrote in message news:[email protected]...
Now I'm really lost. What are you trying to say here?
0 Likes
Message 11 of 19

Anonymous
Not applicable
Murph, Thanks for your reply.

First, I have the VBA written and saved; it is a rather simple VBA that was in a tutorial that I found on this site. I am simply trying to understand how to call the VBA program now by assigning the proper text into a custom button's command line.

Second, in looking at my VBA code, where can I find the sub routine's name? (If I could just learn these 2 things, I can really take off; I am pretty good at learning things and being able to piece things together to get what I need) Here is the code;

Option Explicit

Private Sub CommandButton1_Click()
Dim excelapp As Excel.Application
Dim wbkobj As Workbook
Dim shtobj As Worksheet
On Error Resume Next
excel_launch.Hide
Err.Clear
Set excelapp = GetObject(, "excel.application")
If Err 0 Then
Err.Clear
Set excelapp = CreateObject("excel.application")
If Err 0 Then
MsgBox "Could not start Excel", vbExclamation
End
End If
End If
excelapp.Visible = True
Set wbkobj = excelapp.Workbooks.Add
Set shtobj = excelapp.worsheets(1)
excel_launch.Show
End Sub

Private Sub CommandButton2_Click()
Dim excelapp As Excel.Application
On Error Resume Next
excel_launch.Hide
Err.Clear
Set excelapp = GetObject(, "excel.application")
If Err 0 Then
Err.Clear
MsgBox "No Excel session running.", vbExclamation
End If
excelapp.Quit
excel_launch.Show
End Sub

Private Sub CommandButton3_Click()
End
End Sub

Private Sub UserForm_Click()

End Sub
0 Likes
Message 12 of 19

Anonymous
Not applicable
The code you have goes with a form (dialog box) You need to design the form
with three command buttons on it and name them to match the code. Example:
CommandButton1 to run the sub CommandButton1_Click. Then I would add a sub
like so

Public Sub Main()
UserForm1.Show;;; Userform1 would be the name of your form
End Sub

Now your macro to show the dialog to allow you to click on a button would
be:

^C^C-vbarun "V:/VBA/excel_launch.dvb!Main"

Murph
--
http://mappingitout.blogspot.com/
wrote in message news:[email protected]...
Murph, Thanks for your reply.

First, I have the VBA written and saved; it is a rather simple VBA that was
in a tutorial that I found on this site. I am simply trying to understand
how to call the VBA program now by assigning the proper text into a custom
button's command line.

Second, in looking at my VBA code, where can I find the sub routine's name?
(If I could just learn these 2 things, I can really take off; I am pretty
good at learning things and being able to piece things together to get what
I need) Here is the code;

Option Explicit

Private Sub CommandButton1_Click()
Dim excelapp As Excel.Application
Dim wbkobj As Workbook
Dim shtobj As Worksheet
On Error Resume Next
excel_launch.Hide
Err.Clear
Set excelapp = GetObject(, "excel.application")
If Err 0 Then
Err.Clear
Set excelapp = CreateObject("excel.application")
If Err 0 Then
MsgBox "Could not start Excel", vbExclamation
End
End If
End If
excelapp.Visible = True
Set wbkobj = excelapp.Workbooks.Add
Set shtobj = excelapp.worsheets(1)
excel_launch.Show
End Sub

Private Sub CommandButton2_Click()
Dim excelapp As Excel.Application
On Error Resume Next
excel_launch.Hide
Err.Clear
Set excelapp = GetObject(, "excel.application")
If Err 0 Then
Err.Clear
MsgBox "No Excel session running.", vbExclamation
End If
excelapp.Quit
excel_launch.Show
End Sub

Private Sub CommandButton3_Click()
End
End Sub

Private Sub UserForm_Click()

End Sub
0 Likes
Message 13 of 19

Anonymous
Not applicable
I have the form created; that is where I am running into snags. I am understanding how to create forms; every tutorial I have looked at and tried has showed me how to do that. I can't find a tutorial that tells me how to assign a menu button to call up these forms.

Now, for the sub that you are having me add... does it go at the beginning of my code or at the end, or does that not matter? ( I am sure that is a newbie question)

Question about this sub;

Public Sub Main()
UserForm1.Show;;; Userform1 would be the name of your form
End Sub

Do I type this in EXACTLY as you have it shown, or do I leave out "Userform1 would be the name of your form"?

and finally, is the first line of the sub, "Public Sub Main()"
where the callout "main" comes from in the following;

^C^C-vbarun "V:/VBA/excel_launch.dvb!Main"

I really appreciate all your help! I am finding everything but what I am looking for when I do my own searches!
0 Likes
Message 14 of 19

Anonymous
Not applicable
You need to create a module then add the code in it.
From the VBA editor top menu "Insert > Module Then type this as it is
replacing Userform1 with the name of your form

Public Sub Main()
UserForm1.Show
End Sub


Yes "MAIN" is where the callout comes from in
^C^C-vbarun "V:/VBA/excel_launch.dvb!Main"


Murph
--
http://mappingitout.blogspot.com/

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
wrote in message news:[email protected]...

I have the form created; that is where I am running into snags. I am
understanding how to create forms; every tutorial I have looked at and tried
has showed me how to do that. I can't find a tutorial that tells me how to
assign a menu button to call up these forms.

Now, for the sub that you are having me add... does it go at the beginning
of my code or at the end, or does that not matter? ( I am sure that is a
newbie question)

Question about this sub;

Public Sub Main()
UserForm1.Show;;; Userform1 would be the name of your form
End Sub

Do I type this in EXACTLY as you have it shown, or do I leave out "Userform1
would be the name of your form"?

and finally, is the first line of the sub, "Public Sub Main()"
where the callout "main" comes from in the following;

^C^C-vbarun "V:/VBA/excel_launch.dvb!Main"

I really appreciate all your help! I am finding everything but what I am
looking for when I do my own searches!
0 Likes
Message 15 of 19

Anonymous
Not applicable
A-ha! That did it! everything worked like I wanted it to until I clicked on the 'Quit' button, then I got this error in the command line;
Macro name: "V:/VBA/EXCEL_LAUNCH.dvb!xll" Execution error

Even though I got the error, everything worked like I wanted it to. Any ideas about the error?

And Murph, thanks for the time you are spending with me on this!
0 Likes
Message 16 of 19

Anonymous
Not applicable
Taking a guess but if your Quit button is commandbutton3
you need to change this

Private Sub CommandButton3_Click()
End
End Sub

to

Private Sub CommandButton3_Click()
userform1.hide
End Sub

Murph

--
http://mappingitout.blogspot.com/
wrote in message news:[email protected]...
A-ha! That did it! everything worked like I wanted it to until I clicked
on the 'Quit' button, then I got this error in the command line;
Macro name: "V:/VBA/EXCEL_LAUNCH.dvb!xll" Execution error

Even though I got the error, everything worked like I wanted it to. Any
ideas about the error?

And Murph, thanks for the time you are spending with me on this!
0 Likes
Message 17 of 19

Anonymous
Not applicable
That sealed it. Thank you, Murph!
0 Likes
Message 18 of 19

Anonymous
Not applicable
"Murph" wrote in message
news:[email protected]...
Taking a guess but if your Quit button is commandbutton3
you need to change this

Private Sub CommandButton3_Click()
End
End Sub

to

Private Sub CommandButton3_Click()
userform1.hide
End Sub

actually if that were the button to quit the application (i didn't see the
beginning of this thread)
you might prefer
Private Sub CommandButton3_Click()

Unload Me

End Sub

userform1.hide is like a temporary state where the form is hidden(but still
loaded and running) and presumably brought back to view later in prog with
userform1.show

Unload will close the form and perform any required cleanup provided for in
the Terminate event of the form
0 Likes
Message 19 of 19

Anonymous
Not applicable
Hi,

There is a further difference between:

me.hide and
unload me

In the first case when the form is called again with .show the Activate code
is run whereas if the form was uloaded, both the initialize and activate
code is run.

--
Regards


Laurie Comerford
www.cadapps.com.au
"MP" wrote in message
news:[email protected]...
"Murph" wrote in message
news:[email protected]...
Taking a guess but if your Quit button is commandbutton3
you need to change this

Private Sub CommandButton3_Click()
End
End Sub

to

Private Sub CommandButton3_Click()
userform1.hide
End Sub

actually if that were the button to quit the application (i didn't see the
beginning of this thread)
you might prefer
Private Sub CommandButton3_Click()

Unload Me

End Sub

userform1.hide is like a temporary state where the form is hidden(but still
loaded and running) and presumably brought back to view later in prog with
userform1.show

Unload will close the form and perform any required cleanup provided for in
the Terminate event of the form
0 Likes