Consulting

Results 1 to 7 of 7

Thread: Solved: syntax: shell

  1. #1

    Solved: syntax: shell

    Hi all

    Just a quickie. How do I use the shell function and set the windowstyle variable to vbNormalFocus? In the vba help section it suggests:

    [VBA]Shell("notepad", 1)[/VBA] but the VB editor doesn't like this

    I know you can use [VBA]Shell pathname:="notepad", windowstyle:=1[/VBA]

    but this is not the point. I spent ages trying to get the brackets to work! Does anyone know why this syntax doesn't work/ what the correct syntax is?

    All help much appreciated

    cheers
    silentsound

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    [vba]

    Dim x

    x = Shell("notepad", 1)
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Just lose the brackets.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4

    thanka

    Quote Originally Posted by xld
    [vba]

    Dim x

    x = Shell("notepad", 1)
    [/vba]
    Ah cheers. that explains the error messages!

  5. #5

    Line breaks?

    Further to this, it seems to me that the simplest way to use this command would be to write directly to the command prompt instead of writing to a text file then referencing this later. (correct me if I am wrong btw) Therefore, other than rewriting the command each time is there a way to generate a line break within the shell command? I have tried Googling without success.

    Shell "blah blah";"blah2 blah2"

    instead of

    Shell "blah blah"
    Shell "blah2 blah2"

    So I am basically looking for whatever should replace the semicolon.

    Cheers
    Silentsound

  6. #6
    Not sure what you mean. Why do you need a line break? Do you mean the pipe character '|'? Your 2nd method would work, or put the commands in a batch file and call that with Shell.

  7. #7
    Quote Originally Posted by Crocus Crow
    Not sure what you mean. Why do you need a line break? Do you mean the pipe character '|'? Your 2nd method would work, or put the commands in a batch file and call that with Shell.
    I mean is there a command that I can use such that I can use the shell command once but enclose within the brackets several lines of ftp commands. So I am asking if there is a syntax that will separate lines.

    eg. Shell(host; username; password)

    I want to print host, username and password on separate lines in the command prompt. Basically I was trying to figure out if there is a way to use ftp without a batch file by printing variables straight to the command prompt

Posting Permissions

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