Results 1 to 6 of 6

Thread: [RESOLVED] open file in vb

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    32

    Resolved [RESOLVED] open file in vb

    VB Code:
    1. Sub mnuOpen_Click()
    2.     Dim f As Integer            'for file number
    3.  
    4.     'This first group of commands invokes the Open Dialog
    5.     ' OpenErr1 is invoked if user cancels from Open Dialog
    6.     On Error GoTo OpenErr1
    7.     ' and display the Open dialog (#1)
    8.     CommonDialog1.ShowOpen
    9.  
    10.     ' then get the resulting filename
    11.     FileName = CommonDialog1.FileName
    12.  
    13.     ' Now open a text file
    14.     ' Set the real error handler for file errors
    15.     On Error GoTo OpenErr2
    16.     f = FreeFile
    17.     Open FileName For Input As f
    18.     txtBox.Text = Input$(LOF(f), f) ' Use the better code from the last lesson here
    19.     Close f
    20.  
    21.     ' Nice touch: set the form's caption to contain the filename
    22.     Form1.Caption = "Text Editor : " & FileName
    23.  
    24.     ' this exits if successful open and read
    25.     Exit Sub
    26.  
    27. ' this error handler for actual file errors
    28. OpenErr2:
    29.     MsgBox "Error opening file", vbOK, "Text editor"
    30.     Close f
    31.     Exit Sub
    32.  
    33. ' this error simply exits if user Cancels from Open Dialog
    34. OpenErr1:
    35.     Exit Sub
    36.  
    37. End Sub
    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.
    can anyone help?

    thanks!
    Last edited by Hack; Mar 31st, 2006 at 07:27 AM. Reason: Added [vbcode] [/vbcode] tags for more clarity.

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