locked
help to give me a VB small function RRS feed

  • Question

  • Hi all

     

    I want to capture a excel filename (blablabla.xls) to a variable name.

    but I want to search the file from browser like "Open file"

    can anyone who knows, give me a simple vb function and how to call it???

     

    Thanks for attention

    Tonny

    Monday, March 21, 2011 12:12 PM

Answers

  • Something like the following

    Public Class Form1
    
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
      End Sub
    
      Function GetXLSFilename() As String
        Dim obj1 As New OpenFileDialog
        With obj1
          .Filter = "Xls files|*.xls|All Files|*.*"
          .Multiselect = False
        End With
    
        If obj1.ShowDialog = Windows.Forms.DialogResult.OK Then
          Return obj1.FileName
        Else
          Return ""
        End If
    
      End Function
    
      Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim SelectedFile As String = ""
        SelectedFile = GetXLSFilename()
        Label1.Text = SelectedFile
      End Sub
    End Class
    
    
    • Proposed as answer by Kee Poppy Friday, March 25, 2011 8:13 AM
    • Marked as answer by Kee Poppy Monday, March 28, 2011 5:57 AM
    Monday, March 21, 2011 3:20 PM