Results 1 to 12 of 12

Thread: Text File Shell does not work

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2010
    Posts
    195

    Text File Shell does not work

    Code:
    Shell(Application.StartupPath & "\myfile.txt", vbMaximized Focus)
    The code above shows the error that the file does not exist. But it exists. I tried the same code for an .exe file it works great. Any ideas?
    Last edited by systemous; Apr 3rd, 2011 at 02:12 PM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Text File Shell does not work

    try this:

    vb Code:
    1. Shell(Application.StartupPath & "\myfile.txt", vbMaximized Focus)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2010
    Posts
    195

    Re: Text File Shell does not work

    sorry i added one more quote next to application.startuppath. the code you gave is what i have but nothing.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Text File Shell does not work

    ok. debug.print(Application.StartupPath & "\myfile.txt") + check the path is right

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2010
    Posts
    195

    Re: Text File Shell does not work

    the path is absolutely correct!

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Text File Shell does not work

    ok.

    vb Code:
    1. msgbox(io.file.exists(Application.StartupPath & "\myfile.txt"))

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 2010
    Posts
    195

    Re: Text File Shell does not work

    it returns true. it found the file. :S but shell still dead

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Oct 2010
    Posts
    195

    Re: Text File Shell does not work

    in vb6 the same code would be like that:

    Code:
    Shell("Explorer.exe " & App.Path & "\myfile.txt", vbMaximized Focus)
    but Explorer.exe does not seem to work in vb2010.

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Text File Shell does not work

    Shell is legacy + not used in vb.net
    search for the Process class, in particular Process.Start

  10. #10
    Addicted Member
    Join Date
    Nov 2010
    Location
    TamilNadu, India
    Posts
    249

    Re: Text File Shell does not work

    FIle Code:
    1. Dim _filepath$ = Application.StartupPath & "\myfile.txt"
    2. Process.Start(_filepath)

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Oct 2010
    Posts
    195

    Re: Text File Shell does not work

    proccess.start works great! i tried to add vbMaximizedFocus in procress.start but no result. doesn't it accept that commands?

  12. #12
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Re: Text File Shell does not work

    here ya go, all process start arguments you could use. There are more, but I left those out that you would probably not use.

    vb Code:
    1. Dim p As New Process
    2.         With p.StartInfo
    3.             .FileName = "file name"
    4.             .Arguments = "arguments"
    5.             .CreateNoWindow = False
    6.             .WindowStyle = ProcessWindowStyle.Maximized 'minimized, maximized, normal, hidden
    7.             .WorkingDirectory = "directory of where the application is when started"
    8.             .UseShellExecute = True 'Use shell to start any file, esp. important for "open with" files
    9.             .ErrorDialog = True 'show error dialog if failed to start
    10.         End With
    11.         p.Start() 'start the process
    12.         p.WaitForExit() 'optional: stop code execution until the process exited (closed)

    Not sure about the focus command, but usually newly created windows will take focus any ways.

Posting Permissions

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



Click Here to Expand Forum to Full Width