|
楼主 |
发表于 2024-8-3 15:46
|
显示全部楼层
- Private Sub CopyWorkbooks()
- Dim Str
- Dim Wk As Workbook, Wk1 As Workbook
- Set Wk = ThisWorkbook
- Set Wk1 = Workbooks("TraverseDelFolder.xlsm")
- Dim Win As Window, Win1 As Window
- Set Win = Application.ActiveWindow
- Set Win1 = Application.Windows("TraverseDelFolder.xlsm")
- Dim Sht As Worksheet, Sht1 As Worksheet, oSht As Worksheet
- Dim WkSht As Worksheet, Wk1Sht As Worksheet
- Dim Rng As Range, oRng As Range, oRng1 As Range
- Dim WkRng As Range, Wk1Rng As Range, WkMenuRng As Range
- Debug.Print Wk.Application.Selection.Address
- Set oRng = Wk.Application.Selection
-
- Set WkMenuRng = Wk.Sheets("Menu").Cells(oRng.Row, 1)
-
- Dim Kk, ii, jj
- Kk = 1
- Set Wk1Rng = Win1.Selection
-
- Set Wk1Sht = Wk1Rng.Parent
- With Wk1Rng
- 'Debug.Print .Address, .Parent.Name, .Parent.Parent.Name, .Areas.Count,
- For ii = 1 To .Rows.Count
- If Wk1Rng(ii, 1).MergeCells Then
- Set oRng = Wk1Rng(ii, 1).MergeArea
- oRng(, 2).Resize(oRng.Rows.Count, 3).Copy
- ''
- WkMenuRng(Kk, 1) = Wk1.Name & "!" & Wk1Rng.Parent.Name & "!" & oRng.Address(0, 0)
- Str = Split(oRng(, 1).Value, Chr(10))(0)
-
- Set oSht = AddSheet(ThisWorkbook, Str)
- oSht.Activate
- oSht.Cells(10, "A").PasteSpecial xlPasteAll
- oRng(, 6).Resize(oRng.Rows.Count, 1).Copy
- oSht.Cells(10, "Z").PasteSpecial xlPasteAll
- WkMenuRng(Kk, 2) = Str
- WkMenuRng(Kk, 3) = "=" & Str & "!" & oSht.Cells(10, 1).CurrentRegion.Address(0, 0)
- Kk = Kk + 1
- ii = ii + oRng.Rows.Count - 1
- End If
- Next ii
- End With
- End Sub
复制代码 |
|