怎么用vba把vba代码复制粘贴

2022-03-20 综合 72阅读

试试下面的代码:

Sub Macro1()
    Dim MyPath$, MyName$, sh As Worksheet, m&, w As WorksheetFunction, wb As Workbook
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set w = WorksheetFunction
    MyPath = ThisWorkbook.Path & "\采集多数据"
    MyName = Dir(MyPath & "*.xls*")
    [a1].CurrentRegion.Offset(1).ClearContents
    Do While MyName  ""
            With GetObject(MyPath & MyName)
                With .Sheets(1)
                    If w.CountA(.UsedRange.Offset(1)) Then
                        m = m + 1
                        If m = 1 Then
                            Set wb = Workbooks.Add(xlWBATWorksheet)
                            Set sh = wb.ActiveSheet
                            .[a1].CurrentRegion.Copy sh.[a1]
                        Else
                            .[a1].CurrentRegion.Offset(1).Copy sh.[a65536].End(xlUp).Offset(1)
                        End If
                    End If
                End With
                .Close False
            End With
        MyName = Dir
    Loop
    wb.SaveAs Filename:=ThisWorkbook.Path & "\采集多数据20130422.xls", FileFormat:=xlExcel8
    wb.Close
    Application.ScreenUpdating = True
    MsgBox "ok"
End Sub
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com