如上所述,您可以將信息存儲在(隱藏)表單中,或使用Document Variables。
從文檔:
Sub AddDocumentVariable()
ActiveDocument.Variables.Add Name:="Age", Value:=12
End Sub
這些變量將可即使你的代碼已經完成或工作簿再次關閉和打開。
編輯:(Excel文件,代碼中發現here)
Sub test()
Dim wb As Workbook
Dim docProps As DocumentProperties
Dim docProp As DocumentProperty
Set wb = ActiveWorkbook
Set docProps = wb.CustomDocumentProperties
With docProps
.Add Name:="CustomNumber", _
LinkToContent:=False, _
Type:=msoPropertyTypeNumber, _
Value:=1000
.Add Name:="CustomString", _
LinkToContent:=False, _
Type:=msoPropertyTypeString, _
Value:="This is a custom property."
.Add Name:="CustomDate", _
LinkToContent:=False, _
Type:=msoPropertyTypeDate, _
Value:=Date
End With
For Each docProp In docProps
Debug.Print docProp.Name, docProp.Value
Next
End Sub
嘗試[Workbook.CustomDocumentProperties屬性(Excel)](https://msdn.microsoft.com/en-us/vba/excel-vba/articles/workbook-customdocumentproperties-property-excel)。我從來沒有使用過它,但它可能適用於您的目的。 – YowE3K