Results 1 to 5 of 5

Thread: shell files

  1. #1

    Thread Starter
    Hyperactive Member notquitehere188's Avatar
    Join Date
    Dec 2004
    Posts
    403

    shell files

    if you shell a .txt file will it open it in notepad?
    i ask because it would be easy to run files like that from vb if you did not need to find what had to open them
    It's not just Good, It's Good enough!



    Spelling Eludes Me

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: shell files

    Shell won't open all files, it will run exe/bat files. So you could either shell notepad with the txt file as a parameter for notepad or you can use the ShellExecute API to open the txt file with the associated application.


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    Hyperactive Member notquitehere188's Avatar
    Join Date
    Dec 2004
    Posts
    403

    Re: shell files

    shellexecute api?
    elaborate
    It's not just Good, It's Good enough!



    Spelling Eludes Me

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: shell files

    Examples for both options :

    VB Code:
    1. Shell "notepad C:\file.txt", vbNormalFocus

    Or :

    VB Code:
    1. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    2.  
    3. Const SW_SHOWNORMAL = 1
    4.  
    5. Private Sub Form_Load()
    6.     ShellExecute Me.hwnd, "open", "C:\file.txt", vbNullString, "C:\", SW_SHOWNORMAL
    7. End Sub


    Has someone helped you? Then you can Rate their helpful post.

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: shell files

    The ShellExecute API function is declared in this way:
    VB Code:
    1. Private Declare Function ShellExecute _
    2.  Lib "shell32.dll" Alias "ShellExecuteA" ( _
    3.  ByVal hwnd As Long, _
    4.  ByVal lpOperation As String, _
    5.  ByVal lpFile As String, _
    6.  ByVal lpParameters As String, _
    7.  ByVal lpDirectory As String, _
    8.  ByVal nShowCmd As Long) As Long
    You could use a Sub like the following to open any file:
    VB Code:
    1. Public Sub OpenFile(ByVal sFileName As String)
    2.     ShellExecute 0, "Open", sFileName, vbNullString, vbNullString, vbNormalFocus
    3. End Sub

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