简体   繁体   中英

How to check if VBA module has been modified?

I have an Excel workbook that I would like to export the code for every time the workbook is closed but I would like to do so selectively so that each module will only get exported if it has been modified since the workbook was opened. I would like to be able to use the exported files to run a diff on the code and I'm assuming that re-exporting every time will cause the files to always be flagged as different. Here's an attempt at some pseudo-code to show what I mean:

for each module in Workbook
    if module.isModified() then
        module.export
    end if
next module

VBComponent has a readonly property. Add reference to VBE and you should be able to access "changed" VBComponents

bool Saved

Saved Property - (Excel 2003 VBA Programmer's Reference Google Books)

I was just being lazy about it and hoping someone already new a method that I hadn't found. Sorry about that.

I found that I can use the following.

for each module in Workbook
    if not module.saved then
        module.export
    end if
next module

Then, I'll just run the export function every time the workbook is saved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM