Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 23rd, 2009, 02:26 PM
Authorized User
 
Join Date: Oct 2009
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Application to run excel vba macro

Hello,

I am trying to create an application that looks like this:
http://img406.imageshack.us/img406/7015/picture2so.jpg

So, this is going to be a .exe application that will allow the users to browse for an excel worksheet and with the click of the "Format!" button, it will run the excel vba macro that I have made. What is the best way of doing this? Thanks!
 
Old October 23rd, 2009, 09:47 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

You can create a VB6.0 Application and create a Exe file. You can use CommonDialog in VB Form to select the Excel file.

You can add Excel to the list of References of the VB Project and can use Application.Run to call your macro

If you do not need .EXE, you can create the same application as Excel Workbook and Excel Addin and create the same userform functionality in Excel too

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old October 24th, 2009, 11:56 AM
Authorized User
 
Join Date: Oct 2009
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Shasur! But I think I will be using C++ instead, from this posts that I found:
http://www.codeproject.com/KB/buttons/CBrowseCtrl.aspx
http://www.codeproject.com/KB/office/ExcelwithMC.aspx

Now I got to figure out how to combine these two projects together to do what I want it to do. I also have to figure out if I am able to call a .bas file for Excel to run the macro that I made.

Last edited by dyung2; October 24th, 2009 at 12:49 PM..
 
Old October 26th, 2009, 11:02 AM
Authorized User
 
Join Date: Oct 2009
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay I'm using VB6.0 to create the application and I don't know why I am getting this error: Run-time error '5': Invalid procedure call or argument and it goes back to Shell(Text1.Text)

Here are my codes:
Private Sub btnBrowse_Click()
On Error GoTo MyError
With CommonDialog1
.CancelError = True
.Filter = "Excel Files(*.xls)|*.xls|All files (*.*)|*.*"
.FilterIndex = 1
.Flags = cdlOFNHideReadOnly Or cdlOFNOverwritePrompt Or cdlOFNPathMustExist
.InitDir = App.Path
.ShowOpen
End With
Text1.Text = CommonDialog1.FileName
Exit Sub
MyError:
If Err.Number <> cdlCancel Then
MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation, "Save"
End If
End Sub

Private Sub cmdFormat_Click()
Shell (Text1.Text)
End Sub
 
Old October 26th, 2009, 11:15 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Because shell is a function contained in an API, you need to declare it first (google about it).
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old October 26th, 2009, 11:57 AM
Authorized User
 
Join Date: Oct 2009
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've tried to google but I couldn't find the answer.
If I type in cmd or calc.exe into the textbox and click the button it will run, but if I type in for example "C:\IDS499\Chapter2\google.jpg" I get a run-time error 5.
 
Old October 26th, 2009, 12:06 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Well, it's trying to execute that command. Probably you don't have anything asociated with that kind of file (I doubt it, but according to what you said looks like that).

Anyway, if the command works sometimes and not other, then the problem is not the command, is the input.
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old October 26th, 2009, 07:20 PM
Authorized User
 
Join Date: Oct 2009
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is there any other command to run instead of using Shell because I hard coded Shell("C:\IDS499\Chapter2\google.jpg") and it's still giving me error 5.
 
Old October 26th, 2009, 09:47 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Again.. the problem is not the shell.. what happen is you try to execute that in a command line???
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old October 28th, 2009, 10:57 AM
Authorized User
 
Join Date: Oct 2009
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I figure out a way to fix this problem. Instead of using the Shell command, I used:
Set oWB = oExcel.Workbooks.Open(Text1.Text) and this is perfect! Thanks for all your help!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Schedule a VBA macro to run at a specific time marshall04b Excel VBA 8 October 31st, 2015 08:41 AM
Schedule a VBA macro to run at a specific time peterlihh Other Programming Languages 0 October 24th, 2008 07:15 PM
VBA Macros not showing up in the run macro menu d.lee84 Access VBA 9 August 21st, 2007 09:37 AM
How to add Macro in other OutLook Application VBA kvingupta All Other Wrox Books 0 April 3rd, 2006 05:38 AM
Run macro when exit/close excel dgilford Excel VBA 1 September 8th, 2005 02:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.