对于任一文件的打开操作
写了一段对指定路径文件的操作:
程序1:
Private Sub Command_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
现在想要通过浏览的方式把任意一个文件进行如上操作,又写了一个打开文件的命令:
程序2:
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
因为是新手,不知道如何修改程序1,将其的指定路径改为对程序2已打开的任意文件进行执行操作
请前辈指点
[解决办法]
dim一个变量记录B的文件即可
[解决办法]
定义一个模块级变量即可