vba excel代码,vba excel操作网页

首页 > 实用技巧 > 作者:YD1662023-05-12 07:07:02

在Excel菜单栏中,点击开发工具,打开VBA,输入如下代码:

vba excel代码,vba excel操作网页(9)

其中代码如下所示:

Sub 合并目录所有工作簿全部工作表()

Dim MP, MN, AW, Wbn, wn

Dim Wb As Workbook

Dim i, a, b, d, c, e

Application.ScreenUpdating = False

MP = ActiveWorkbook.Path

MN = Dir(MP & "\" & "*.xls")

AW = ActiveWorkbook.Name

Num = 0

e = 1

Do While MN <> ""

If MN <> AW Then

Set Wb = Workbooks.Open(MP & "\" & MN)

a = a 1

With Workbooks(1).ActiveSheet

For i = 1 To Sheets.Count

If Sheets(i).Range("a1") <> "" Then

Wb.Sheets(i).Range("a1").Resize(1, Sheets(i).UsedRange.Columns.Count).Copy .Cells(1, 1)

d = Wb.Sheets(i).UsedRange.Columns.Count

c = Wb.Sheets(i).UsedRange.Rows.Count - 1

wn = Wb.Sheets(i).Name

.Cells(1, d 1) = "表名"

.Cells(e 1, d 1).Resize(c, 1) = MN & wn

e = e c

Wb.Sheets(i).Range("a2").Resize(c,d).Copy .Cells(.Range("a1048576").End(xlUp).Row 1, 1)

End If

Next

Wbn = Wbn & Chr(13) & Wb.Name

Wb.Close False

End With

End If

MN = Dir

Loop

Range("a1").Select

Application.ScreenUpdating = True

MsgBox "共合并了" & a & "个工作薄下全部工作表。如下:" & Chr(13) & Wbn, vbInformation, "提示"

End Sub

天天有小伙伴说,教程太简单,整点高端的,我就不解释代码了,大家有需求的直接用代码合并,欢迎留言讨论,点赞,转发

-------------------------

欢迎关注,更多精彩内容持续更新中....

上一页123末页

栏目热文

文档排行

本站推荐

Copyright © 2018 - 2021 www.yd166.com., All Rights Reserved.