Results 1 to 4 of 4

Thread: How run Excel macro from ACAD

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2003-03
    Posts
    1

    Question How run Excel macro from ACAD

    Hi,
    Does anyone know how to activate/run from ACAD a routine MACRO (in VBA) in EXCEL?

    I have some macros (VBA) in EXCEL, and they works very well in Excel …

    I have some routines in ACAD (in Vlisp) that let me communicate ACAD with EXCEL from ACAD (send and get dates from and to Excel cells and Acad variables -lisp defined-).

    I look for one routine in ACAD that let me run one of this macros –based on the input defined by user Macro-Excel name - (using the original macro programmed in Excel without need make a new macro in Acad –the same as in Excel- ).
    Really I would like one LISP routine (or in VB) to run one Excel-routine (VBA).

    Help is needed...
    Best regards
    Troncosoft

  2. #2
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,210

    Default Re: How run Excel macro from ACAD

    Quote Originally Posted by tsaracho View Post
    Hi,
    Does anyone know how to activate/run from ACAD a routine MACRO (in VBA) in EXCEL?

    I have some macros (VBA) in EXCEL, and they works very well in Excel …

    I have some routines in ACAD (in Vlisp) that let me communicate ACAD with EXCEL from ACAD (send and get dates from and to Excel cells and Acad variables -lisp defined-).

    I look for one routine in ACAD that let me run one of this macros –based on the input defined by user Macro-Excel name - (using the original macro programmed in Excel without need make a new macro in Acad –the same as in Excel- ).
    Really I would like one LISP routine (or in VB) to run one Excel-routine (VBA).

    Help is needed...
    Best regards
    Troncosoft
    Try this one

    Code:
    (defun C:RM (/ abks aexc asht find x xbks xlpath xshts)
    (if (not (findfile
    (setq xlpath (strcat (getvar "dwgprefix")
    "TestMacros"
    ".xls"))));<-- full path of your Excel file, change to suit
    (progn
    (alert "File does not exist")
    (exit)
    (princ)
    )
    )
    (alert "Close Excel File Save Changes")
     
    (setq aexc (vlax-get-or-create-object "Excel.Application")
    xbks (vlax-get-property aexc "Workbooks"))
    (if (not (vl-file-systime xlpath))
    (progn (setq find nil)
    (setq abks (vlax-invoke-method xbks "Add")))
    (progn (setq find T)
    (setq abks (vlax-invoke-method xbks "Open" xlpath)))
    )
    (setq xshts (vlax-get-property abks "Sheets")
    asht (vlax-get-property xshts "Item" 1)) ;<-- sheet number - optional not used in this program
    (vla-put-visible aexc :vlax-true)
    (vlax-put-property aexc "ScreenUpdating" :vlax-true) ; to see changes
    (vlax-put-property aexc "DisplayAlerts" :vlax-true) ; to initialize user interaction
    (vlax-invoke-method asht "Activate") ;optional not used in this program
    (vlax-invoke-method
    aexc
    "Run"
    (strcat (vl-filename-base xlpath) ".xls!MyMacro")) ;<-- macro name in the Excel file
    (vlax-invoke-method
    abks
    'SaveAs
    xlpath
    -4143
    nil
    nil
    :vlax-false
    :vlax-false
    1
    2
    )
    (mapcar
    (function (lambda (x)
    (vl-catch-all-apply
    (function (lambda ()
    (progn
    (if x
    (vlax-release-object x))))))))
    (list asht
    xshts
    abks
    xbks
    aexc)
    )
    (setq aexc nil)
    (gc)
    (gc)
    (princ)
    )
     
    (princ "\nType RM to run macros")
    (princ)
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

  3. #3
    Woo! Hoo! my 1st post
    Join Date
    2010-01
    Posts
    1

    Default Re: How run Excel macro from ACAD

    what would be the difference in code to automatically save and close excel file after macro job without involving user interaction?
    actually part of your code after calling macro is kinda blurry to me..

  4. #4
    Forum Manager, Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    4,776

    Default Re: How run Excel macro from ACAD

    Welcome to augi.

    If you go directly to the vba forum, in the upper right is a link called "Search this forum". A search on 'excel' returned 179 threads. Also, if you installed the sample files with acad, there is a vba project for extracting attributes to excel that gives you some sample code.
    C:> ED WORKING....

Similar Threads

  1. Macro to extract Attributes to Excel
    By jbortoli in forum VBA/COM Interop
    Replies: 5
    Last Post: 2010-06-06, 07:55 AM
  2. Access Excel from ACAD
    By csorensen in forum CAD Management - General
    Replies: 23
    Last Post: 2010-02-12, 06:22 PM
  3. Acad & Excel
    By MikeJarosz in forum VBA/COM Interop
    Replies: 5
    Last Post: 2008-05-20, 03:46 PM
  4. ACAD Macro or LISP not working in ABS
    By jason.combs in forum AMEP General
    Replies: 9
    Last Post: 2006-08-16, 08:33 PM
  5. printing acad with excel in the dwg
    By RCA4697 in forum AutoCAD General
    Replies: 2
    Last Post: 2005-03-23, 04:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •