Author Topic: vba project using activex  (Read 1797 times)

0 Members and 1 Guest are viewing this topic.

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
vba project using activex
« on: November 13, 2007, 12:01:02 PM »
Is it possible to create a vba project and the insert an empty module using activex?
Just to make the following function work.
Code: [Select]
(defun Test (/ AcadObj ActiveCodePaneObj CodeModuleObj Name VBEObj)
  (setq Name (getstring "\nEnter your name: " t))
  (setq AcadObj (vlax-get-acad-object))
  (setq VBEObj (vla-get-VBE AcadObj))
  (setq ActiveCodePaneObj (vlax-get-property VBEObj 'ActiveCodePane))
  (setq CodeModuleObj (vlax-get-property ActiveCodePaneObj 'CodeModule))
  (vlax-invoke-method
    CodeModuleObj
    'AddFromString
    (strcat "Sub Test()\nMsgBox \"" "Hello " Name "\"\nEnd Sub")
  )
  (vl-vbarun "Test")
  (foreach Obj (list AcadObj VBEObj ActiveCodePaneObj CodeModuleObj)
    (vlax-release-object Obj)
  )
  (gc)
)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vba project using activex
« Reply #1 on: November 13, 2007, 12:28:35 PM »
Tip 1: Before you invoke AddFromString you must ensure you're not trying to establish a Function or Sub that already exists.

Tip 2: Use the Find function to determine it for you (over simplified in interests of brevity) --

Code: [Select]
(vlax-invoke
    codeModuleObj
   'Find
    "Sub Test"                             ;; What
    0                                      ;; StartLine
    0                                      ;; StartColumn
    (vlax-get codeModuleObj 'CountOfLines) ;; EndLine
    100                                    ;; EndColum
)

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: vba project using activex
« Reply #2 on: November 13, 2007, 04:58:31 PM »
thanks MP, but i need somthing to start with, i can not make vla-Add to add a new vba project. as soon as i find the way out, i will engage in error checking and so on...