Board logo

標題: [發問] 簡化重複的 for each ... in [打印本頁]

作者: s13030029    時間: 2019-7-25 08:44     標題: 簡化重複的 for each ... in

請問要怎樣簡化下面這段程式嗎????
  1. For Each Abar In Application.CommandBars
  2.         If Not Abar.BuiltIn Then Abar.Delete
  3.     Next

  4.     For Each Bbar In Application.CommandBars
  5.         If Not Bbar.BuiltIn Then Bbar.Delete
  6.     Next

  7.     For Each Cbar In Application.CommandBars
  8.         If Not Cbar.BuiltIn Then Cbar.Delete
  9.     Next

  10.     For Each Dbar In Application.CommandBars
  11.         If Not Dbar.BuiltIn Then Dbar.Delete
  12.     Next

  13.     For Each Ebar In Application.CommandBars
  14.         If Not Ebar.BuiltIn Then Ebar.Delete
  15.     Next

  16.     For Each Fbar In Application.CommandBars
  17.         If Not Fbar.BuiltIn Then Fbar.Delete
  18.     Next
複製代碼

作者: s13030029    時間: 2019-7-26 09:12

回復 1# s13030029
用陣列的方式,已解決~~~
    bbar = Array(bar1, bar2, bar3, bar4, bar5, bar6)
    For Each bbar In Application.CommandBars
        If Not bbar.BuiltIn Then bbar.Delete
    Next




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)