Excel VB Shell, ShellExecute Cannot get to workk. HELP GURUS

sharpescalade

New Member
Joined
Sep 13, 2006
Messages
5
THANK YOU SO MUCH FOR YOUR TIME!!! THANK YOU!
I know I MUST be doing something STUPID....

I am working SOLELY with OFFICE/EXCEL 2003 SP2
MACRO Security set to LOW


I have tried the entire DAY to get this to work.

Simple as this:

I have a excel document, it has some VB for a splash screen, and graphic indicators...

Nothing really special.. I am still working on it....

I want to use excel and the VB editor to launch different programs and FILES during different times....

I keep seeing many variations of SHELL and SHELLEXECUTE.....but none "cut and pasted" with my "file or program actual path" added will work.... I keep getting "Compile Error: Invalid Outside Procedure"...

even when i try a basic shell command such as:

Shell ("Explorer")

I get an error
(maybe its where and how I am doing the code)

=====================
NOTE: the SHELL explorer command I just picked for now to get things working.... i have other uses, but i dont want to use a complicated code until I can get a basic SHELL command working.
======================

I am simply:

1. making new excel base document
2. going to VB Editor(right click,code or ALT-F11)
3. creating a NEW MODULE
4. Pasting:

Shell ("Explorer")

5. Saving the document
6. Restarting the excel document
7. Then I get the VB editor popping up, and a error dialog box, "Compile Error: Invalid Outside Procedure"... and the "Shell ("Explorer") highlighted in yellow.....

(And just to check, if this worked, shouldnt I open the document, and then explorer would open as well???)

I was really unsure of where to put the shell commands as well... because one needs to startup when anyone opens the excel document, to minimize all windows, and just leave the splash screen up, then it times out and the actual excel document shows up...(at least thats my plan)..right now I have the splash, timer and document working...but I need the SHELL command to(when you start the excel document) minimize all the windows to the taskbar......which I was simply going to tell excel to SHELL to the "SHOW DESKTOP" command or link or something....(its actually a .scf file in windows, kind of a executable I guess)

and there needs to be some SHELL commands that will be controlled by command/userform buttons(How I can do this, hell I dont know)

note: all my SHELL commands will be linked to FILES and Programs... I dont need to import or export any excel data...... ALSO I need to understand all the variations of SHELL windows settings for ASYNC,SYNC working, MAXIMIZED/MINIMIZED(focused??) windows....

so really.. i need to know what the heck I am doing wrong and why no shell commands, even basic ones, wont run at all...

and I need to find out how to SHELL to minimize all windows, except my splash screen... then the excel doc will load after time-out...

then... i need to know how to SHELL via buttons on userforms or however people normally do it.......

note: I looked into doing some of this by marcos, but controlling and processing macros via VB looked like a huge PAIN........

THANK YOU SO MUCH FOR YOUR TIME!!! THANK YOU!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
8,253
Office Version
  1. 2016
Platform
  1. Windows
Hi sharpescalade,

If I understand you propperly, you are getting this error because you are not placing the Shell command inside a Procedure.

You should put the command like this:

Code:
Sub Test

      Shell "explorer"

End Sub

Regards.
 

sharpescalade

New Member
Joined
Sep 13, 2006
Messages
5
hmmm

no i dont think i am....DOH!.... so after adding the procedure.. where should I put the whole SHELL then?.. a MODULE? or can i just put it in the worksheet "view code"....? or userform view code???

will the placement determine when the SHELL executes??

and can someone address some of the issues I am having still?


THANK YOUUUUUU!!!!!!!!!!!!
 

sharpescalade

New Member
Joined
Sep 13, 2006
Messages
5
help?

can anyone help me with the things I listed in the original post??? PLEASE THANK YOU SOO MUCH!

also.....after that... i understand about placing a SHELL command inside of a procedure... and I added the SHELL inside a procedure.... BUT i am still uncertain of where to even PUT these codes... there is [VIEW CODE/add code in there] of EACH spreadsheet, and then [VIEW CODE/add code in there] for "THIS WORKBOOK".. and even I can insert a MODULE and [VIEW CODE/add code in there]..... whats the difference of adding code in each of these parts???

back to my changes... so I SHELL command inside of my procedure...1st I place the code in the "View Code" of the spreadsheet....save, reopen, and nothing..... THEN I CUT the code and place it into the "View Code" of "This Workbook"....save, reopen....nothing starts auto.. but i CAN RUN A MACRO(which was not there before) and the basic SHELL of:

Sub Test

Shell "explorer"

End Sub

...runs explorer... OOO something works!.. but wait....!

I have several SHELL command I need to run via:

1. Auto on startup of excel file(when splash comes up, SHELL command that minimizes all windows, except the splash, then EXCEL window pops up. I already have it that when you open my excel, EXCEL minimizes, splash comes up and auto-times out then EXCEL pops back up. But I need a SHELL to command windows to minimize all open windows(except the ones I want of course)

2. I need to run some SHELLs via controls... how can I use a form, place a button/whatever, and have it run a SHELL??

THANK YOU FOR YOUR HELP!
 

Damon Ostrander

MrExcel MVP
Joined
Feb 17, 2002
Messages
4,239
Hi sharp,

I must commend you on your persistence, by which I feel compelled to reply.

Regarding where to place the code, it mostly depends on how you plan to run it. If you would like to run the code using menu Tools > Macro > Macros or via a keyboard shortcut (like Ctrl-Y), then putting it in a standard macro module is the way to go. Also, putting it in a standard macro module and making it public by not placing a Private keyword in front of it (e.g., "Private Sub Test") means that it is visible from other modules in the workbook, including ThisWorkbook, worksheet, and userform modules, and therefore can be called from within their code using "Call Test" or just "Test".

But there are good reasons why you might want to put it in one of the other types of modules:

worksheet code modules - you should put it in a worksheet event code module if either a) its use is associated with only one sheet, and you never want it to be able to run it if another sheet is active, or b) you want to trigger it to run when something occurs on the associated worksheet, such as a certain cell being selected or having data entered, or a button on that sheet being clicked, etc. For example, say you want Test to run when the user enters a value of "hello" in cell B4. Then you would put the following code in the worksheet's code module:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.Address = "$B$4" Then
      Test
   End If
End Sub

Sub Test
   Shell "explorer"
End Sub

ThisWorkbook code module - you should put it in the workbook event code module if you want it to be automatically triggered to run when something occurs on any worksheet (again, things like a particular cell being edited or selected) or you want it to run when the workbook first opens, or when it is saved or closed. As an example of this, let's say you want test to run when the workbook first opens. You would add this code to the ThisWorkbook code module:

Code:
Private Sub Workbook_Open()
   Test
End Sub

Sub Test
   Shell "explorer"
End Sub

Userform code module - you should put it in the userform event code module if it is associated only with a userform--i.e., it is to be triggered by some event on the userform such as a userform button click, checkbox select, etc., and will not be called from any other module in the workbook. An example of this would be to run Test when a button named DoneBtn on a userform is clicked by placing this code in the userform's code module:

Code:
Private Sub DoneBtn_Click()
   Test
End Sub

Sub Test
   Shell "explorer"
End Sub

I believe this also answers your question about running the shell based on a userform event.

I hope you find this explanation helpful.

I'm not sure what the shell command would be to minimize all open windows except for certain ones.

Damon
 

Forum statistics

Threads
1,136,655
Messages
5,677,017
Members
419,668
Latest member
DharmaK

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top