Results 1 to 5 of 5

Run Macro in Excel from Autocad

Threaded View

  1. #1
    Registered User
    Join Date
    03-11-2010
    Location
    SINGAPORE
    MS-Off Ver
    Excel 2007
    Posts
    12

    Unhappy Run Macro in Excel from Autocad

    Hi all,
    i have almost completed my project, but i am facing a problem.
    I have a VBA program ( in ACAD), that opens a workbook and retrieve the data to generate drawings , based on excel cells values; this works perfectly.
    Now , i want my ACAD program to load this same WB in excel, then execute a macro (based in the excel WB), then when complete continue to run the program in ACAD.
    Before the first Excel macro is executed, it needs to get a value from ACAD user form input box, then use it for its macro ( Excel).
    So my the question is in the title : how i can run the macro in excel from ACAD ?
    i cannot figure out the code associated to this. Hope it is clear.
    This is the code i try to run the macro:
    it opens the excel sheet, but then excel freeze as soon as it passes the line "run..."
    Sub DrawCablesFromExcelFile(FileNameAndPath As String, SheetName As String)
        Dim MyXL As Object
        Dim ExcelFound As Boolean
    
        ' Check if Excel is running.
        On Error Resume Next
        
        Set MyXL = GetObject(, "Excel.Application")
        
        If Err.Number <> 0 Then ExcelFound = True
        Err.Clear    ' Clear Err object in case error occurred.
    
        ExcelFound = DetectExcel
    
        ' Set the object variable to reference the file you want to use.
        Set MyXL = GetObject(FileNameAndPath)
    
        ' Show Microsoft Excel.
        MyXL.Application.Visible = True
        MyXL.Parent.Windows(1).Visible = True
        
        ' Draw in AutoCAD
        Dim TrayWidth As Double, TrayHeight As Double, CableDia As Double
        Dim NoRows As Double, NoCols As Double, i As Integer, r As Integer, Tray2Check As String, ODCheck As Object
        
        '**********************
        '   Recherche du Node dans le cable schedule et mise n Forme pour le traitement CAD
        '**********************
        MyXL.Application.Run "Schedule4Trays.xlsm!ODCheck"
        
        
        '***********************************
        ' Logique de tri dans Excel et dessin du cable
        '************************************
        r = 2
         
        With MyXL.Sheets("Sheet1")
            .Activate

    Thanks for your help.
    Last edited by Breizh29; 03-29-2010 at 08:24 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1