Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a Document 2

Status
Not open for further replies.

besto1a

Programmer
Aug 20, 2006
41
GB
How do I open a document from my application, all I want to do is open the document, word, excel etc seperate from my application

Thanks
 
system.diagnostics.process.start("c:\file.xls")
 
Sorry,

I need to select the file i need in a diaplog box click open and have the document open seperate to my applciations
 
1) Use a form with a textbox and 2 buttons and a FileOpenDialog.

2) Label one button OK, and the other Open. Name the Open button bFile and follow the code below.

3) Hook the FileOpenDialog Filename to the textbox.

Something like this:

Code:
Private Sub bFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bFile.Click
        OD = New OpenFileDialog
        With OD
            .Filter = "FoxPro Programs|*.prg|FoxPro Tables|*.dbf|Applications|*.exe"
            .Title = "Open Fox Pro Program"
            .ShowDialog()
        End With
        If OD.FileName <> "" Then
            Try
                txtPRG.Text = OD.FileName
            Catch ex As Exception
                MsgBox("Error: " & ex.Message)
            End Try
        End If
    End Sub

To launch your file once it has been chosen, either use the Shell function or the system.diagnostics.process.start, as suggested by TipGiver, behind the OK button event.

BTW, TipGiver is great, so anything he gives you is gold.

I hope this helps.



Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Thank you Ron for your kind... words? (is this the right phrase in english? lol)

I was going to post two lines, but i could not reach the server. The first was the .ShowDialog() and the other the process.start(OD.filename). (* without checking is the use selected a file at all)

Ron, just i little thing you did not write. As i see, you did not draged and drop an OpenFileDialog control, but instead created one at runtime. Just add 'Dim OD As OpenFileDialog' at the start of the bfile click event handler.

Something else:
> txtPRG.Text = OD.FileName
I dont think that it can throw any exeption. Or i missed something ?

Thanks again.
 
Ron, just i little thing you did not write.

> Sorry my stupid. You may have declared out of it so the OD variable had class-scope visibility.

 
TipGiver,

.. or have Option Strict / Option Explicit set to OFF


Hope this helps.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top