解决方案 | vb记住上次打开的文件夹

 
 Private Sub Button_ImportBasicData_Click(sender As Object, e As EventArgs) Handles Button_ImportBasicData.Click
     ' 创建文件对话框对象
     Dim openFileDialog As New OpenFileDialog()

     ' 配置文件对话框
     openFileDialog.Title = "请选择一个Excel文件"
     openFileDialog.Filter = "Excel 文件 (*.xlsx; *.xls)|*.xlsx;*.xls"
     openFileDialog.InitialDirectory = ""


     ' 显示文件对话框
     If openFileDialog.ShowDialog() = DialogResult.OK Then
         Dim filePath As String = openFileDialog.FileName
         ' 在此处添加打开和处理Excel文件的代码
         MsgBox("您选择的文件是: " & filePath)
     Else
         MsgBox("没有选择文件")
     End If
 End Sub

 

 

关键代码:设置初始文件夹为空

openFileDialog.InitialDirectory = ""

 

posted @ 2024-05-21 17:11  IssacNew  阅读(14)  评论(0编辑  收藏  举报