|
楼主 |
发表于 2024-7-31 07:56
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub llll()
- Dim Rng As Range
- Set Rng = Selection
- Debug.Print Rng.Address
- Stop
- Dim oRng As Range
- Set oRng = Rng(, 0).MergeArea
- Debug.Print oRng.Address
- Stop
- End Sub
复制代码 '''
- Function MergeRng(Rng As Range)
- Dim LastRow, FirstRow
- Dim ii, jj
- Dim oRng As Range
-
- Dim Sht As Worksheet
- Set Sht = Rng.Parent
- With Rng.Parent
- LastRow = Rng.Row + Rng.Rows.Count - 1
- For ii = Rng.Row + Rng.Rows.Count - 1 To 2 Step -1
- If .Cells(ii, Rng.Column).Value <> .Cells(ii - 1, Rng.Column).Value Then
- FirstRow = ii
- If FirstRow < Rng.Row Then
- Exit Function
- End If
- .Cells(FirstRow, Rng.Column).Resize(LastRow - FirstRow + 1, 1).Merge
- LastRow = ii - 1
- End If
- Next ii
- Set oRng = Rng.MergeArea
- End With
- End Function
- ''
- Function MergeRetuFolderFile(Fso As FileSystemObject, Rng As Range)
- Dim Sht As Worksheet
- Set Sht = Rng.Parent
- Dim oFile As File
- Dim oFolder1 As Folder, oFolder2 As Folder, oFolder3 As Folder
- Dim oSize
- Dim oStr
- Dim oRng As Range, oRng1 As Range
- For jj = 1 To 3
- For ii = 1 To Rng.Rows.Count
- Set oRng = Rng(ii, jj)
- If oRng.MergeCells Then
- Set oRng = oRng.MergeArea
- With oRng
- .HorizontalAlignment = xlLeft
- .VerticalAlignment = xlTop
- End With
- oRng.Select
- 'Debug.Print oRng.Address, oRng(1, 1).Address, oRng(, "H")
- With Sht
- oStr = .Cells(oRng(, 1).Row, "H")
- End With
-
- Set oFile = Fso.GetFile(oStr)
-
- Set oFolder3 = oFile.ParentFolder
- Set oFolder2 = oFolder3.ParentFolder
- Set oFolder1 = oFolder2.ParentFolder
- Select Case jj
- Case 1
- Set oRng1 = Sht.Cells(oRng(, 1).Row, "F").Resize(oRng.Rows.Count, 1)
- oSize = WorksheetFunction.Sum(oRng1)
- oStr = oFolder1.Name & Chr(10) & "SubFolder" & oFolder1.SubFolders.Count & Chr(10) & "Files:" & oRng.Rows.Count & Chr(10) & "Size:" & oSize & "MB"
- Sht.Hyperlinks.Add Anchor:=Selection, Address:=oFolder1.Path, TextToDisplay:=oStr
- Case 2
- Set oRng1 = Sht.Cells(oRng(, 1).Row, "F").Resize(oRng.Rows.Count, 1)
- oSize = WorksheetFunction.Sum(oRng1)
- oStr = oFolder2.Name & Chr(10) & "SubFolder" & oFolder2.SubFolders.Count & Chr(10) & "Files:" & oRng.Rows.Count & Chr(10) & "Size:" & oSize & "MB"
- Sht.Hyperlinks.Add Anchor:=Selection, Address:=oFolder2.Path, TextToDisplay:=oStr
- Case 3
- Set oRng1 = Sht.Cells(oRng(, 1).Row, "F").Resize(oRng.Rows.Count, 1)
- oSize = WorksheetFunction.Sum(oRng1)
- oStr = oFolder3.Name & Chr(10) & "Files:" & oRng.Rows.Count & Chr(10) & "Size:" & oSize & "MB"
- Sht.Hyperlinks.Add Anchor:=Selection, Address:=oFolder3.Path, TextToDisplay:=oStr
- End Select
- oRng(, 1) = oStr
- 'Debug.Print oFolder1.Path, oFolder2.Path, oFolder3.Path
- ii = ii + oRng.Rows.Count
- End If
- Next ii
- Next jj
- End Function
复制代码
|
|