return to form after shell command

I am pretty new to VB, but I managed to build a small Application. The App works fine but I have a question about it.

The App contains 1 form with a few textboxes and one button. When the user fills the texboxes and click the button the Windows Explorer opens a specific folder and the application/form closes.

Is it possible to return to the form? I only want the application to close when the user closes it via 'X'..

thx for your help!



  • seancampbellseancampbell Pennsylvania, USA
    If the application is closed, there is no way to re open it without executing the application again... chances are you wont find a nice solution to know when the Windows Explorer form closes to re-execute the software.

    In a similar scenario, I would simply leave the Form open or tell the form to minimize itself. This way, the user can go back to the app once he finishes with Explorer.
  • txx for your reply. What code do i need to insert to let the form open?
    The Windows Explorer window is a sperate one anyway...So I just want the form to stay open untill the user hits 'x'

  • seancampbellseancampbell Pennsylvania, USA
    If the Form closes when the Windows Explorer window comes up, its probably because you are calling the line "Me.Close" in that routine... The form will not close itself, it only closes when it is told to...

    So instead of "inserting" code to leave the form opened, you need to remove code, a line that says "Me.Close()" or "Form.Close()"
  • I don't have such command in my code. Here is the code:

    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


    End Sub
    Sub Opener(

    Dim hd As String = TextBox1.Text & ":"
    Dim hdlocation As String
    Dim hdlocation2 As String
    Dim folder As String = TextBox2.Text

    If ComboBox1.Text = "games" Then GoTo games Else GoTo apps


    hdlocation = hd & "01_Archief_Digitaalgames"

    Shell("Explorer.exe " & hdlocation & folder, vbNormalFocus,)



    hdlocation2 = hd & "01_Archief_Digitaalapps"

    Shell("Explorer.exe " & hdlocation2 & folder, vbNormalFocus)


    End Sub

    End Class
  • seancampbellseancampbell Pennsylvania, USA

    Do you understand your own code? Not trying to bash you, just wondering...

    Anyway, remove these lines:
    (not End Sub)

    End, by itself, closes the application...
    Unlike Application.Exit or Me.Close() (note, me.close only closes the application if the form that is closing was designated as the start up form, or passed to Application.Run in the Sub Main) it will not allow the application to call Form_Closing and Form_Closed, it staight up ENDS execution...

    Hope this helps
  • Thank you man! I am new to this and the End commands where there because I converted the code from VBA (Excel)

    I replaced the End commands with Exit sub.

    The App runs as i want it to work now!!!!


  • seancampbellseancampbell Pennsylvania, USA
    Awesome! Glad I could help,
    Take Care
    Sean C
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!