p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Microsoft Office > Excel VBA > Excel VBA
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 23rd, 2009, 03:26 PM
Registered User
Points: 56, Level: 1
Points: 56, Level: 1 Points: 56, Level: 1 Points: 56, Level: 1
Activity: 35%
Activity: 35% Activity: 35% Activity: 35%
 
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old October 23rd, 2009, 10:47 PM
Friend of Wrox
Points: 1,449, Level: 15
Points: 1,449, Level: 15 Points: 1,449, Level: 15 Points: 1,449, Level: 15
Activity: 17%
Activity: 17% Activity: 17% Activity: 17%
 
Join Date: Sep 2005
Location: , , .
Posts: 420
Thanks: 0
Thanked 14 Times in 14 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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old October 24th, 2009, 12:56 PM
Registered User
Points: 56, Level: 1
Points: 56, Level: 1 Points: 56, Level: 1 Points: 56, Level: 1
Activity: 35%
Activity: 35% Activity: 35% Activity: 35%
 
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 01:49 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old October 26th, 2009, 12:02 PM
Registered User
Points: 56, Level: 1
Points: 56, Level: 1 Points: 56, Level: 1 Points: 56, Level: 1
Activity: 35%
Activity: 35% Activity: 35% Activity: 35%
 
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old October 26th, 2009, 12:15 PM
Friend of Wrox
Points: 6,570, Level: 34
Points: 6,570, Level: 34 Points: 6,570, Level: 34 Points: 6,570, Level: 34
Activity: 43%
Activity: 43% Activity: 43% Activity: 43%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,000
Thanks: 5
Thanked 37 Times in 36 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.
================================================== =========
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old October 26th, 2009, 12:57 PM
Registered User
Points: 56, Level: 1
Points: 56, Level: 1 Points: 56, Level: 1 Points: 56, Level: 1
Activity: 35%
Activity: 35% Activity: 35% Activity: 35%
 
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old October 26th, 2009, 01:06 PM
Friend of Wrox
Points: 6,570, Level: 34
Points: 6,570, Level: 34 Points: 6,570, Level: 34 Points: 6,570, Level: 34
Activity: 43%
Activity: 43% Activity: 43% Activity: 43%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,000
Thanks: 5
Thanked 37 Times in 36 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.
================================================== =========
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #8 (permalink)  
Old October 26th, 2009, 08:20 PM
Registered User
Points: 56, Level: 1
Points: 56, Level: 1 Points: 56, Level: 1 Points: 56, Level: 1
Activity: 35%
Activity: 35% Activity: 35% Activity: 35%
 
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #9 (permalink)  
Old October 26th, 2009, 10:47 PM
Friend of Wrox
Points: 6,570, Level: 34
Points: 6,570, Level: 34 Points: 6,570, Level: 34 Points: 6,570, Level: 34
Activity: 43%
Activity: 43% Activity: 43% Activity: 43%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,000
Thanks: 5
Thanked 37 Times in 36 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.
================================================== =========
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #10 (permalink)  
Old October 28th, 2009, 11:57 AM
Registered User
Points: 56, Level: 1
Points: 56, Level: 1 Points: 56, Level: 1 Points: 56, Level: 1
Activity: 35%
Activity: 35% Activity: 35% Activity: 35%
 
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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



All times are GMT -4. The time now is 05:35 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc