|
|
 |
| 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.
|
 |

October 23rd, 2009, 03:26 PM
|
|
Registered User
|
|
Join Date: Oct 2009
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|

October 23rd, 2009, 10:47 PM
|
|
Friend of Wrox
|
|
Join Date: Sep 2005
Location: , , .
Posts: 420
Thanks: 0
Thanked 14 Times in 14 Posts
|
|
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
|

October 24th, 2009, 12:56 PM
|
|
Registered User
|
|
Join Date: Oct 2009
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

October 26th, 2009, 12:02 PM
|
|
Registered User
|
|
Join Date: Oct 2009
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

October 26th, 2009, 12:15 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,000
Thanks: 5
Thanked 37 Times in 36 Posts
|
|
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.
================================================== =========
|

October 26th, 2009, 12:57 PM
|
|
Registered User
|
|
Join Date: Oct 2009
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

October 26th, 2009, 01:06 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,000
Thanks: 5
Thanked 37 Times in 36 Posts
|
|
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.
================================================== =========
|

October 26th, 2009, 08:20 PM
|
|
Registered User
|
|
Join Date: Oct 2009
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

October 26th, 2009, 10:47 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,000
Thanks: 5
Thanked 37 Times in 36 Posts
|
|
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.
================================================== =========
|

October 28th, 2009, 11:57 AM
|
|
Registered User
|
|
Join Date: Oct 2009
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |