VB2008 如何调用OpenFileDiaglogBox打开的文件?
自己在程序中用了OpenFileDiaglogBox请问要编写什么代码让程序能够用OpenFileDiaglogBox中自己选择的文件呢?
有一个按钮Button1
请问如何自己选择一个xls文件后,点确定,程序自动打开此文件? --------------------编程问答-------------------- //选择完你的程序文件后..
...
Prcess.Start(文件名带路径);
即可... --------------------编程问答--------------------
Public Class Form1
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Integer, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Integer) As Long
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.InitialDirectory = "c:\"
openFileDialog1.Filter = "excel files (*.xls)|*.xls|All files (*.*)|*.*"
openFileDialog1.FilterIndex = 1
openFileDialog1.RestoreDirectory = True
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
ShellExecute(Me.Handle, "open", openFileDialog1.FileName, vbNullString, vbNullString, 1)
Catch Ex As Exception
MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
End Try
End If
End Sub
End Class
补充:VB , 基础类