您可以使用:
- (defun Load_And_Run_VBA(File Procedure / cFile)
- (vl-load-com)
-
- (defun Get_VBP_List(/ cPr cPat VBPrj pQnt pCnt prLst)
-
- (setq VBPrj(vlax-get
- (vla-get-VBE
- (vlax-get-acad-object))
- 'VBProjects)
- pQnt(vla-get-Count VBPrj)
- pCnt 1)
- (repeat pQnt
- (setq cPr(vla-Item VBPrj pCnt))
- (if(vl-catch-all-error-p
- (setq cPat(vl-catch-all-apply
- 'vlax-get(list cPr 'FileName))))
- (setq prLst(cons "*Invalid Project*" prLst))
- (setq prLst(cons cPat prLst))
- ); end if
- (setq pCnt(1+ pCnt))
- ); end repeat
- prLst
- ); end of Get_VBP_List
- (if(setq cFile(findfile File))
- (progn
- (if(not(member cFile(Get_VBP_List)))
- (vl-vbaload cFile)
- ); end if
- (vl-vbarun Procedure)
- ); end progn
- (princ
- (strcat "\n<!> Can't to find VBA Project: '"
- File "' <!> "))
- ); end if
- (princ)
- ); end of Load_And_Run_VBA
例如:
- (Load_And_Run_VBA "C:\\My VBA Routines\\My program.dvb" "MyProcedure")
此代码检查已加载*的列表。dvb文件和加载VBA程序仅一次,但每次都会运行。 |