当前位置:编程学习 > VB >>

[求助]导入一个指定名称的外部数据XLS文档

同一文件夹内有多个外部数据(XLS格式的)
我需要将其中一个指定名称的外部数据(比如本拉丹.xls)导入到模板的工作表[外部数据]中,如果这些外部数据里没有我想要的外部数据,还需要有个提示框来提示。
导入一个指定名称的外部数据XLS文档到模板的指定工作表[外部数据],如果外部文档中没有指定名称的话,程序将提示用户,且程序不会报错
但下面的程序导入时要报错,请问我如何修改?
Sub 导入xls() 
    Dim wk As Workbook, Sht As Worksheet, n As Integer, MyPath, MyName, u As Integer, arr, deSht$
    Dim myr&, I1&
Application.ScreenUpdating = False
Application.EnableEvents = False
    n = 0: m = 0
    MyPath = ThisWorkbook.Path
    MyName = Dir(MyPath & "\" & "*.xls")
    With ThisWorkbook
        Sheets("外部数据").Cells.Clear
        Do While MyName <> ""
            deSht = ""
            If MyName <> .Name Then
                Select Case MyName
                   Case "本拉丹.xls": deSht = "外部数据"
                End Select
                If Len(deSht) = 0 Then GoTo PP
                Set wk = Workbooks.Open(MyPath & "\" & MyName)
                m = m + 1
                For Each Sht In wk.Sheets
                    arr = Sht.UsedRange
                    If IsArray(arr) = False Then GoTo PP
                    n = n + 1
                    With .Sheets(deSht)
                        u = .UsedRange.Row + .UsedRange.Rows.Count
                        .Cells(u, 1).Interior.ColorIndex = 6
                        .Cells(u, 1) = wk.Name & "-" & Sht.Name
                        .Cells(u + 1, 1).Resize(UBound(arr), UBound(arr, 2)) = arr
                    End With
                    Erase arr
PP:
                Next
                wk.Close False
            End If
            MyName = Dir
        Loop
  End With
Application.ScreenUpdating = True
Application.EnableEvents = True
    ThisWorkbook.Worksheets("首页").Select
End Sub
--------------------编程问答-------------------- --------------------编程问答-------------------- 二楼是什么意思? --------------------编程问答--------------------
引用 2 楼 lhj323323 的回复:
二楼是什么意思?


他说他是一大臭道士,念了一句咒语:meiganjue,meignasuoha,没感觉,就馊了。
补充:VB ,  VBA
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,