+ Reply to Thread
Results 1 to 13 of 13

Shell Function "Compile Error: Expected procedure, not variable"

  1. #1
    Registered User
    Join Date
    11-08-2013
    Location
    Oslo
    MS-Off Ver
    Excel 2003
    Posts
    5

    Shell Function "Compile Error: Expected procedure, not variable"

    I have a VBA shell script that worked just fine on another computer, but now it won't run.

    The code that won't execute is:
    Please Login or Register  to view this content.
    This gives the error message: "Compile Error: Expected procedure, not variable", which to me indicates that the Shell command is not recogniced.

    Have also teste a bunch of other syntaxes (eg. using WScript). This returns other errors (eg. Variable not defined for WScript)

    As the code worked before (on another computer) and none of the other shell syntaxes works, I suspect that the problem is related to a dependency to a library reference, or that there is some kind of a conflict between different libraries that uses Shell as a keyword. I have activated "Microsoft Shell Controls And Automatation" and some other libraries that i hoped would work, but so far without any luck.

    Does anyone know how to solve this?

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Shell Function "Compile Error: Expected procedure, not variable"

    Hi and welcome to ExcelForum,

    Thank you for using CODE TAGS.

    Chances are there is a missing VBA reference to one of the basic VBA runtime libraries. Chip Pearson references 5 basic librararies, which are the only ones I have loaded on my Excel 2003 computer, and your code compiles and runs on my machine if I use
    'c:\Windows\system32\Write.exe'.

    For Chip's list of the libraries see: http://www.cpearson.com/excel/missingreferences.aspx

    Lewis

  3. #3
    Registered User
    Join Date
    11-08-2013
    Location
    Oslo
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Shell Function "Compile Error: Expected procedure, not variable"

    Ty for a Quick Reply! It seems that I am missing one of the libraries. I will post an update when I have tried the solution.

  4. #4
    Registered User
    Join Date
    11-08-2013
    Location
    Oslo
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Shell Function "Compile Error: Expected procedure, not variable"

    Quote Originally Posted by LJMetzger View Post
    Hi and welcome to ExcelForum,
    Chip Pearson references 5 basic librararies, which are the only ones I have loaded on my Excel 2003 computer [...] http://www.cpearson.com/excel/missingreferences.aspx
    Lewis
    Turns out that the missing reference library (RegistryWorx) was not part of the 5 basic librararies, but an additional library that I could download from cpearson. I have now tried the "Detect And Repair option" that the article sugguested and also tried to reduce my references to only the 5 essential libraries without anny change in the results. As the macro worked on your computer with the same libraries I wonder If there are any security options that I'm missing? anny other sugguestions? (I have excel 2010 BTW)

  5. #5
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Shell Function "Compile Error: Expected procedure, not variable"

    Perhaps your program and .txt file are not in the same location on both computers.

    Do c:\Windows\Write.exe and c:\Test.txt exist on the computer the shell command is not working on?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  6. #6
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Shell Function "Compile Error: Expected procedure, not variable"

    Quote Originally Posted by Solus Rankin View Post
    Perhaps your program and .txt file are not in the same location on both computers.
    When I was missing one or both of the above items in Excel 2003, the code compiled fine. There was a problem at runtime because of the missing resource(s).

    Lewis

  7. #7
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Shell Function "Compile Error: Expected procedure, not variable"

    @ LJ Metzger

    I suppose it would since its compiles as a string.

  8. #8
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Shell Function "Compile Error: Expected procedure, not variable"

    It seems like there is something missing that does not recognize the 'Shell' command.

  9. #9
    Registered User
    Join Date
    11-08-2013
    Location
    Oslo
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Shell Function "Compile Error: Expected procedure, not variable"

    Just to clarify: Both files are on the same computer. The code is just an example of how the Shell syntax that worked on my work computer does not work on my home computer. LJMetzger have tested the same code and got it to work on his computer with the same libraries that I have activated on my homecomputer, indicating that its not a problem with the syntax in it self and that the correct libraries are activated.

    Quote Originally Posted by Solus Rankin View Post
    Perhaps your program and .txt file are not in the same location on both computers.

    Do c:\Windows\Write.exe and c:\Test.txt exist on the computer the shell command is not working on?

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Shell Function "Compile Error: Expected procedure, not variable"

    Does VBA.Shell work?
    Entia non sunt multiplicanda sine necessitate

  11. #11
    Registered User
    Join Date
    11-08-2013
    Location
    Oslo
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Shell Function "Compile Error: Expected procedure, not variable"

    Quote Originally Posted by shg View Post
    Does VBA.Shell work?
    This solved my problem! :D Thankyou very much!

    The new code that work is:
    Please Login or Register  to view this content.
    Seems strange that I needed to use a different syntax on this computer than the others. Any thoughts on why?
    My home computer have excel 2010 while the "call shell" syntax worked on my work computer with a newer version of excel and Excel 2003 (acording to LJMetzger).

  12. #12
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Shell Function "Compile Error: Expected procedure, not variable"

    Quote Originally Posted by shg View Post
    Does VBA.Shell work?
    Great job shg. Shell and VBA.Shell both work on my Vista 32 bit computer with Excel 2003.

    Lewis

  13. #13
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Shell Function "Compile Error: Expected procedure, not variable"

    Any thoughts on why?
    My suspicion is that you have a namespace confilict -- a variable, procedure, or module named Shell someplace. From the error message, it's a variable. Search the project.
    Last edited by shg; 08-09-2014 at 01:22 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Compile Error - "Expected array "- when declaring a string variable??
    By wazimu13 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-09-2013, 03:20 PM
  2. [SOLVED] Problem with calling another macro (Error 450 and " Expected variable or procedure")
    By Roxner in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-07-2013, 04:59 AM
  3. [SOLVED] Problem with "Compile error: Expected Fuction or variable"
    By perducci in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-21-2012, 11:59 AM
  4. Mac issue (please help) "Compile error: Expected Function or variable"
    By m1notaur in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-22-2011, 06:00 PM
  5. [SOLVED] function "compile error msg: procedure too large"
    By RASHESH in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-13-2005, 12:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1