返回列表 上一主題 發帖

[發問] 模組是否能夠不侷限於單一excel檔案

本帖最後由 GBKEE 於 2012-6-1 07:25 編輯

回復 3# alumi
  1. '建立一模組名稱為主程式內的程序
  2. Option Explicit
  3. Private Sub Auto_Open()              '檔案開啟時自動執行的程式
  4.     Dim xlvbe As Variant, xlArray(), xlPath As String
  5.     xlPath = "D:\模組區\"                                   '模組存放路進
  6.     xlArray = Array("模組1.bas", "模組2.bas", "模組3.bas")  '陣列:更新的模組
  7.     With ThisWorkbook.VBProject
  8.         For Each xlvbe In .VBComponents
  9.             If xlvbe.Name <> "主程式" And xlvbe.Type = vbext_wt_Designer Then  'xlVba.Type = 1 模組
  10.                 .VBComponents.Remove xlvbe             '移除所有模組 不包含"主程式"
  11.             End If
  12.         Next
  13.         For Each xlvbe In xlArray
  14.             If Dir(xlPath & xlvbe) <> "" Then .VBComponents.Import xlPath & xlvbe
  15.             'Import 匯入模組
  16.         Next
  17.     End With
  18. End Sub
複製代碼

TOP

        靜思自在 : 願要大、志要堅、氣要柔、心要細。
返回列表 上一主題