|
楼主 |
发表于 2024-1-9 03:46
|
显示全部楼层
本帖最后由 ning84 于 2024-1-9 10:53 编辑
Pptx文件反复执行SaveAs 命令,文件会增加很大。
96M文件增加到336M
- Sub TraverseFolderDeleteRow()
- Dim Fso As FileSystemObject, oFile As File
- Set Fso = New FileSystemObject
- Dim Rng As Range, oRng As Range
- Dim Sht As Worksheet
- Set Rng = Selection
- Set Sht = Rng.Parent
- Set Rng = Sht.Cells(25, 1).CurrentRegion
- Debug.Print Rng.Address
- For ii = 1 To Rng.Rows.Count
- PathName = ThisWorkbook.Path & "" & Sht.Name & "" & Rng(ii, 2)
- Debug.Print Rng(ii, 2), Fso.FileExists(PathName)
- If Fso.FileExists(Path) = False Then
- Rng(ii, 1).Resize(, 26).Select
- Rng(ii, 1).Resize(, 26).Delete
- End If
- Next ii
- End Sub
复制代码
程序在优化一次。
- Sub TraverseFolderDeleteRow()
- Dim Fso As FileSystemObject, oFile As File
- Set Fso = New FileSystemObject
- Dim Rng As Range, oRng As Range, oRng1 As Range
- Dim Sht As Worksheet
- Set Rng = Selection
- Set Sht = Rng.Parent
- Set Rng = Sht.Cells(25, 1).CurrentRegion
- 'Debug.Print Rng.Address
- For ii = 1 To Rng.Rows.Count
- PathName = ThisWorkbook.Path & "" & Sht.Name & "" & Rng(ii, 2)
- ''
- 'Debug.Print Rng(ii, 2), Fso.FileExists(PathName)
- 'Debug.Print PathName
- '''
- If Fso.FileExists(PathName) = False Then
- If oRng Is Nothing Then
- Set oRng = Rng(ii, 1).Resize(, 26)
- Else
- Set oRng = Union(oRng, Rng(ii, 1).Resize(, 26))
- End If
- 'Debug.Print oRng.Address
- oRng.Select
- 'Rng(ii, 1).Resize(, 26).Select
-
- 'Rng(ii, 1).Resize(, 26).Delete
- Else
- Set oFile = Fso.GetFile(PathName)
- 'Debug.Print oFile.Path
- 'Stop
- End If
- Next ii
- Debug.Print oRng.Address, oRng.Areas.Count
- Stop
- oRng.Delete
- End Sub
复制代码
|
|