|
楼主 |
发表于 2024-7-14 01:58
|
显示全部楼层
本帖最后由 ning84 于 2024-7-14 06:45 编辑
- Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
- Dim Rng As Range
- Set Rng = Selection
-
- Dim Sht As Worksheet
- Set Sht = Rng.Parent
- With Sht
- Rng = Selection
- If Rng.Column <= 8 Then
- Set Rng = .Cells(Rng.Row, "H")
- ElseIf Rng.Column = 9 Then
- Set Rng = .Cells(Rng.Row, "J")
- Else
- Set Rng = .Cells(Rng.Row, Rng.Column)
- End If
- Debug.Print Rng.Address
- Rng.Hyperlinks.Add Rng, Rng
-
-
- End With
- End Sub
- Sub llll()
- Dim Fso As FileSystemObject
- Set Fso = New FileSystemObject
- Dim Rng As Range, oRng As Range, oRng1 As Range
- Set Rng = Selection
- Dim Sht As Worksheet
- Dim oFile As File
- Dim oFolder1 As Folder, oFolder2 As Folder, oFolder3 As Folder
- Dim oSize
- Set Sht = Rng.Parent
- With Sht
- Set Rng = .Range(.Cells(4, 1).Formula)
- End With
- Debug.Print Rng.Address
- For jj = 1 To 3
- For ii = 3 To Rng.Rows.Count
- Set oRng = Rng(ii, jj)
- If oRng.MergeCells Then
- Set oRng = oRng.MergeArea
- '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)
- oRng(, 1) = oFolder1.Name & Chr(10) & "SubFolder" & oFolder1.SubFolders.Count & Chr(10) & "Files:" & oRng.Rows.Count & Chr(10) & "Size:" & oSize & "MB"
- Case 2
- Set oRng1 = Sht.Cells(oRng(, 1).Row, "F").Resize(oRng.Rows.Count, 1)
- oSize = WorksheetFunction.Sum(oRng1)
- oRng(, 1) = oFolder2.Name & Chr(10) & "SubFolder" & oFolder2.SubFolders.Count & Chr(10) & "Files:" & oRng.Rows.Count & Chr(10) & "Size:" & oSize & "MB"
- Case 3
- Set oRng1 = Sht.Cells(oRng(, 1).Row, "F").Resize(oRng.Rows.Count, 1)
- oSize = WorksheetFunction.Sum(oRng1)
- oRng(, 1) = oFolder3.Name & Chr(10) & "Files:" & oRng.Rows.Count & Chr(10) & "Size:" & oSize & "MB"
- End Select
- 'Debug.Print oFolder1.Path, oFolder2.Path, oFolder3.Path
- ii = ii + oRng.Rows.Count
- End If
- Next ii
- Next jj
- End Sub
复制代码
- Function MergeRng(Rng As Range)
- Dim LastRow, FirstRow
- Dim ii, jj
- 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
- 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 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
- '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)
- oRng(, 1) = oFolder1.Name & Chr(10) & "SubFolder" & oFolder1.SubFolders.Count & Chr(10) & "Files:" & oRng.Rows.Count & Chr(10) & "Size:" & oSize & "MB"
- Case 2
- Set oRng1 = Sht.Cells(oRng(, 1).Row, "F").Resize(oRng.Rows.Count, 1)
- oSize = WorksheetFunction.Sum(oRng1)
- oRng(, 1) = oFolder2.Name & Chr(10) & "SubFolder" & oFolder2.SubFolders.Count & Chr(10) & "Files:" & oRng.Rows.Count & Chr(10) & "Size:" & oSize & "MB"
- Case 3
- Set oRng1 = Sht.Cells(oRng(, 1).Row, "F").Resize(oRng.Rows.Count, 1)
- oSize = WorksheetFunction.Sum(oRng1)
- oRng(, 1) = oFolder3.Name & Chr(10) & "Files:" & oRng.Rows.Count & Chr(10) & "Size:" & oSize & "MB"
- End Select
- 'Debug.Print oFolder1.Path, oFolder2.Path, oFolder3.Path
- ii = ii + oRng.Rows.Count
- End If
- Next ii
- Next jj
- End Function
复制代码
|
-
|