I am working on batch processes and have some files with Embedded VBA Projects. This has spread to several files now because of our work flow - open an old file, save with a new name. Attached is the dialog that is displayed when the files are opened in the editor. I would like to "extract" the embedded macros in .NET. They do not need to be there and they interupt the batch processes. I know I could un-check the "Always ask before opening projects with macros" but I would rather extract / remove them.
Solved! Go to Solution.
Solved by Jeff_M. Go to Solution.
Here is Lisp written by Jeff Mishler
See if that helps to see algorithms
(defun c:rvba (/ adoc cnt dicts)
(vl-load-com)
(setq adoc (vla-get-activedocument
(vlax-get-acad-object)
)
dicts (vla-get-dictionaries adoc)
)
(if (not (vl-catch-all-error-p
(setq vba_dict (vl-catch-all-apply
(function (lambda ()
(vla-item dicts "ACAD_VBA")
)
)
)
)
)
)
(progn
(setq cnt 0)
(vlax-for a vba_dict
(vla-delete a)
(setq cnt (1+ cnt))
)
)
(alert (strcat "Unloaded " (itoa cnt) " VBA project(s)")))
(gc)
(princ)
)
(c:rvba)
(princ)
This seems to work in the limited testing I've done:
public class testing: IExtensionApplication { #region IExtensionApplication Members public void Initialize() { Application.DocumentManager.DocumentCreated += new DocumentCollectionEventHandler(DocumentManager_DocumentCreated); } void DocumentManager_DocumentCreated(object sender, DocumentCollectionEventArgs e) { using (Transaction tr = e.Document.Database.TransactionManager.StartTransaction()) { DBDictionary nod = (DBDictionary)e.Document.Database.NamedObjectsDictionaryId.GetObject(OpenMode.ForRead); try { DBDictionary dict = (DBDictionary)tr.GetObject(nod.GetAt("ACAD_VBA"), OpenMode.ForWrite); dict.Erase(); } catch { } tr.Commit(); } } public void Terminate() { } #endregion }