主题:[讨论]commondialog1多选和单选问题
commondialog1多选和单选问题,数组FileName默认是从0开始,选一个文件时没有任何问题,但多选时FileName(0)为文件路径,这样程序会直接结束。没有任何动作。
如果设定数组从1开始,新的问题来了。选多个文件没有问题。但单个文件就会出问题,请问老师我该如何处理这个问题。谢谢。下面是代码
Private Sub Command1_Click()
Dim PName(), Ppath, Z, st
Dim FindPos, k ', ir
Dim s$, j&, shName$, arr1()
Dim xlApp As Object '
Dim xlBook As Object '
Dim xlsheet As Object '
On Error Resume Next
CommonDialog1.CancelError = True
' Set flags
CommonDialog1.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
' Set filters
CommonDialog1.Filter = "Text Files (*.txt)|*.txt"
' Display the Save dialog box
CommonDialog1.FileName = ""
CommonDialog1.ShowOpen
FileName = Split(CommonDialog1.FileName, Chr(0))
' x = 1
Set xlApp = CreateObject("Excel.Application") '
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open("D:\work\template.xls") '
Set xlsheet = xlBook.Sheets(1) '
xlsheet.Activate '
With xlsheet
While x <= UBound(FileName)
objectfso (FileName(x))
.Cells(65536, (k - 1) * 4 + 12).End(xlUp).Offset(1).Resize(i, 3) = Application.Transpose(arr) x = x + 1
Wend
end with
。。
。。
如果设定数组从1开始,新的问题来了。选多个文件没有问题。但单个文件就会出问题,请问老师我该如何处理这个问题。谢谢。下面是代码
Private Sub Command1_Click()
Dim PName(), Ppath, Z, st
Dim FindPos, k ', ir
Dim s$, j&, shName$, arr1()
Dim xlApp As Object '
Dim xlBook As Object '
Dim xlsheet As Object '
On Error Resume Next
CommonDialog1.CancelError = True
' Set flags
CommonDialog1.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
' Set filters
CommonDialog1.Filter = "Text Files (*.txt)|*.txt"
' Display the Save dialog box
CommonDialog1.FileName = ""
CommonDialog1.ShowOpen
FileName = Split(CommonDialog1.FileName, Chr(0))
' x = 1
Set xlApp = CreateObject("Excel.Application") '
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open("D:\work\template.xls") '
Set xlsheet = xlBook.Sheets(1) '
xlsheet.Activate '
With xlsheet
While x <= UBound(FileName)
objectfso (FileName(x))
.Cells(65536, (k - 1) * 4 + 12).End(xlUp).Offset(1).Resize(i, 3) = Application.Transpose(arr) x = x + 1
Wend
end with
。。
。。