本帖最后由 张雄友 于 2015-2-12 18:08 编辑
Open 环境下 False 与 True 的用法,近段时间读了很多遍历文件的例子,
有个疑问:什么时候用wb.Close True,什么时候用 wb.Close False ?.php?mod=viewthread&tid=843771&extra=page%3D1%26filter%3Dtypeid%26typeid%3D16%26typeid%3D16
.html
Sub 删除空行()
Dim sh As Worksheet, w As WorksheetFunction, Filepath, LastRow As Long, NowRow As Long, MyPath$
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = ThisWorkbook.Path & ""
If .Show = False Then Exit Sub
MyPath = .SelectedItems(1) & ""
End With
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Set d = CreateObject("scripting.dictionary")
Set w = Application.WorksheetFunction
Filepath = GetName(MyPath)
For kk = 0 To UBound(Filepath)
Set wb = Workbooks.Open(Filepath(kk))
For Each sh In wb.Sheets
LastRow = sh.UsedRange.Row - 1 + sh.UsedRange.Rows.Count
If w.CountA(sh.UsedRange) > 0 Then
For NowRow = LastRow To sh.UsedRange.Row Step -1
If Application.WorksheetFunction.CountA(sh.Rows(NowRow)) = 0 Then
sh.Rows(NowRow).Delete
End If
Next NowRow
End If
Next
'什么时候用wb.Close True,什么时候用 wb.Close False ?????????????????
'此例只能用True 为什么不是用 False ???
wb.Close True 'wb.Close True可以实现删除,但是 wb.Close False 就不做工了,怎么用法???????? Next
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "OK"
End Sub
Function GetName(lj As String)
Dim MyName, dic, Did, i, t, F, tt, MyFileName
Set dic = CreateObject("Scripting.Dictionary")
Set Did = CreateObject("Scripting.Dictionary")
dic.Add (lj), ""
i = 0
Do While i < dic.Count
Ke = dic.Keys
MyName = Dir(Ke(i), vbDirectory)
Do While MyName <> ""
If MyName <> "." And MyName <> ".." Then
If (GetAttr(Ke(i) & MyName) And vbDirectory) = vbDirectory Then
dic.Add (Ke(i) & MyName & ""), ""
End If
End If
MyName = Dir
Loop
i = i + 1
Loop
For Each Ke In dic.Keys
MyFileName = Dir(Ke & "*.xls*")
Do While MyFileName <> ""
If MyFileName <> ThisWorkbook.Name Then Did.Add (Ke & MyFileName), ""
MyFileName = Dir
Loop
Next
GetName = Did.Keys
End Function
2015-2-12 18:01 上传
点击文件名下载附件
29.21 KB, 下载次数: 1
本文发布于:2024-01-28 05:14:32,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17063900785045.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |