原本我的程序是通过在程序中指定路径打开特定的文件直接操作的
现在想加添加一个open钮并在textbox中显示打开的文件名
再按执行键对所打开的文件进行操作现在我把两个程序分别贴出来
请大大们帮我进行连接
执行单一路径指定文件Private Sub Command1_Click()
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim lsFileName As String
Dim llRow As Long
Dim llCol As Long
Dim lsTemp As String
Dim n() As String
lsFileName = App.Path & "\sjdm"
llRow = 0
Set xlBook = xlApp.Workbooks.Add()
Set xlsheet = xlBook.Worksheets(1)
Open lsFileName & ".dat" For Input As #1
Do While Not EOF(1)
Line Input #1, lsTemp
n = Split(lsTemp, Chr(9))
Debug.Print lsTemp
llRow = llRow + 1
For llCol = 0 To UBound(n)
xlsheet.Cells(llRow, llCol + 1) = n(llCol)
Next
Loop
Close #1
xlBook.SaveAs lsFileName & ".xls"
xlBook.Close (True)
xlApp.Quit
Set xlApp = Nothing
End Sub文件浏览打开程序:
Private Sub CmdOpen_Click()
On Error Resume Next
CdlTest.CancelError = True
CdlTest.DialogTitle = "打开文件"
CdlTest.FileName = ""
CdlTest.Filter = "所有文件 (*.*)|*.*"
CdlTest.Flags = cdlOFNCreatePrompt + cdlOFNHideReadOnly
CdlTest.ShowOpen
If Err = cdlCancel Then Exit Sub
TextBoxOPen.Text = CdlTest.FileName
End Sub如果需要源文件我可以发给大大,请亲自指教
现在想加添加一个open钮并在textbox中显示打开的文件名
再按执行键对所打开的文件进行操作现在我把两个程序分别贴出来
请大大们帮我进行连接
执行单一路径指定文件Private Sub Command1_Click()
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim lsFileName As String
Dim llRow As Long
Dim llCol As Long
Dim lsTemp As String
Dim n() As String
lsFileName = App.Path & "\sjdm"
llRow = 0
Set xlBook = xlApp.Workbooks.Add()
Set xlsheet = xlBook.Worksheets(1)
Open lsFileName & ".dat" For Input As #1
Do While Not EOF(1)
Line Input #1, lsTemp
n = Split(lsTemp, Chr(9))
Debug.Print lsTemp
llRow = llRow + 1
For llCol = 0 To UBound(n)
xlsheet.Cells(llRow, llCol + 1) = n(llCol)
Next
Loop
Close #1
xlBook.SaveAs lsFileName & ".xls"
xlBook.Close (True)
xlApp.Quit
Set xlApp = Nothing
End Sub文件浏览打开程序:
Private Sub CmdOpen_Click()
On Error Resume Next
CdlTest.CancelError = True
CdlTest.DialogTitle = "打开文件"
CdlTest.FileName = ""
CdlTest.Filter = "所有文件 (*.*)|*.*"
CdlTest.Flags = cdlOFNCreatePrompt + cdlOFNHideReadOnly
CdlTest.ShowOpen
If Err = cdlCancel Then Exit Sub
TextBoxOPen.Text = CdlTest.FileName
End Sub如果需要源文件我可以发给大大,请亲自指教
Dim xlBook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim lsFileName As String
Dim llRow As Long
Dim llCol As Long
Dim lsTemp As String
Dim n() As String
CdlTest.CancelError = True
CdlTest.DialogTitle = "打开文件"
CdlTest.FileName = ""
CdlTest.Filter = "所有文件 (*.*)|*.*"
CdlTest.Flags = cdlOFNCreatePrompt + cdlOFNHideReadOnly
CdlTest.ShowOpen
If Err = cdlCancel Then Exit Sub
lsFileName = CdlTest.FileName llRow = 0
Set xlBook = xlApp.Workbooks.Add()
Set xlsheet = xlBook.Worksheets(1)
Open lsFileName & ".dat" For Input As #1
Do While Not EOF(1)
Line Input #1, lsTemp
n = Split(lsTemp, Chr(9))
Debug.Print lsTemp
llRow = llRow + 1
For llCol = 0 To UBound(n)
xlsheet.Cells(llRow, llCol + 1) = n(llCol)
Next
Loop
Close #1
xlBook.SaveAs lsFileName & ".xls"
xlBook.Close (True)
xlApp.Quit
Set xlApp = Nothing
添加好excel和dialog控件后
只能执行第一个打开程序
后面一个command bottom执行不了对打开文件的操作
现实错误 要求对象
请问哪里错了
感觉大大是把两段语言合并成一个了
但执行时错误为找不到文件我是想通过两个command键实现浏览打开和执行请问该如何改进