彰化一整天的論壇

 找回密碼
 立即註冊
查看: 330|回復: 0

word 刪除空白的儲存格

[複製鏈接]
發表於 2016-11-30 08:44:06 | 顯示全部樓層 |閱讀模式
  1. Sub DeleteEmptyTablerowsandcolumns()
  2. Application.ScreenUpdating = False
  3. Dim Tbl As Table, cel As Cell, i As Long, n As Long, fEmpty As Boolean
  4. With ActiveDocument
  5. For Each Tbl In .Tables
  6. n = Tbl.Columns.Count
  7. For i = n To 1 Step -1
  8. fEmpty = True
  9. For Each cel In Tbl.Columns(i).Cells
  10. If Len(cel.Range.Text) > 2 Then
  11. fEmpty = False
  12. Exit For
  13. End If
  14. Next cel
  15. If fEmpty = True Then Tbl.Columns(i).Delete
  16. Next i
  17. Next Tbl
  18. End With
  19. With ActiveDocument
  20. For Each Tbl In .Tables
  21. n = Tbl.Rows.Count
  22. For i = n To 1 Step -1
  23. fEmpty = True
  24. For Each cel In Tbl.Rows(i).Cells
  25. If Len(cel.Range.Text) > 2 Then
  26. fEmpty = False
  27. Exit For
  28. End If
  29. Next cel
  30. If fEmpty = True Then Tbl.Rows(i).Delete
  31. Next i
  32. Next Tbl
  33. End With
  34. Set cel = Nothing: Set Tbl = Nothing
  35. Application.ScreenUpdating = True
  36. End Sub
複製代碼
文章來源: https://www.extendoffice.com/doc ... lumns-in-table.html
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

 ㄚ母滴雞湯
 員林香純滴雞精

Archiver|手機版|小黑屋|彰化一整天的論壇(Excel,Office)  |网站地图

GMT+8, 2018-7-23 05:46 , Processed in 0.028668 second(s), 10 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表