vba

一、将一个workbook拆分为多个workbook

Sub cf()

Dim wk As Workbook, ss$, k%

Application.DisplayAlerts = False

For Each sht In Workbooks("1").Sheets

Set wk = Workbooks.Add

k = k + 1

Workbooks(1).Sheets(k).Copy Workbooks(2).Sheets(1)

ss = ThisWorkbook.Path & "\" & sht.Name & " .xlsx"

wk.SaveAs ss

wk.Close

Next

Application.DisplayAlerts = True

MsgBox ("Its done")

End SubL�

二、add workbook

Sub nm()

Dim s As Workbook

Set s = Workbooks.Add

s.SaveAs Workbooks(1).Path & "\123.xlsx"

End Sub

三、open all files

Sub nm()

Dim a$, n!, wbs As Workbook

a = Dir("c:\*.xlsx")

Workbooks.Open Workbooks(1).Path & a

Do

a = Dir

If a <> "" Then

Workbooks.Open Workbooks(1).Path & a

Else

Exit Sub

End If

Loop

End Sub

三、sheets

Sub nm()

Dim k As Integer

k = 1

For Each i In Sheets

k = k + 1

Cells(k, 2) = i.name

Next

End Sub

四、add sheets

Sub nm()

For i = 12 To 1 Step -1

Sheets.Add.name = i & "month"

Next

End Sub

五、删除sheets

sheets().delete

application.displayalerts=false

六、move、copy、select

Sub nm()

Sheets("4month").Activate

End Sub

1⃣️选择所有工作表

Sheets.Select

你可能感兴趣的:(vba)