i've tried to use this command to open a file (word/excel) in vb but it said "error opening file".i was hoping that i could open it in vb itself (in text box or OLE or frame) and not in word/excel so that i can edit the data in vb.VB Code:
Sub mnuOpen_Click() Dim f As Integer 'for file number 'This first group of commands invokes the Open Dialog ' OpenErr1 is invoked if user cancels from Open Dialog On Error GoTo OpenErr1 ' and display the Open dialog (#1) CommonDialog1.ShowOpen ' then get the resulting filename FileName = CommonDialog1.FileName ' Now open a text file ' Set the real error handler for file errors On Error GoTo OpenErr2 f = FreeFile Open FileName For Input As f txtBox.Text = Input$(LOF(f), f) ' Use the better code from the last lesson here Close f ' Nice touch: set the form's caption to contain the filename Form1.Caption = "Text Editor : " & FileName ' this exits if successful open and read Exit Sub ' this error handler for actual file errors OpenErr2: MsgBox "Error opening file", vbOK, "Text editor" Close f Exit Sub ' this error simply exits if user Cancels from Open Dialog OpenErr1: Exit Sub End Sub
can anyone help?
thanks!




Reply With Quote