Results 1 to 6 of 6

Thread: VLisp and Excel: Making Certain Sheet Active

Threaded View

  1. #1
    Member freedomonek's Avatar
    Join Date
    2006-05
    Location
    Columbus, Oh
    Posts
    48

    Post VLisp and Excel: Making Certain Sheet Active

    Hello,
    I need a little help with a small protion of a routine.
    I have layer info in an Excel file by several Sheets (labeled by discipline). ie: Architectural, Structural, etc..
    Within the Code I first ask for user's input to select discipline. If the user selects "M" for Mechanical, the mechanical sheet would becomes active to gather data.

    The Routine works with the with one active sheet in Excel, but the problem is that I can't find the code to make a specific sheet active.

    Would you be able to help me.

    Thanks!
    Kelley

    Code:
    (defun c:test ()
    (initget 1 "Architectural Civil Demolition Electrical General Hvac Instrumentation Mechanical Plumbing Structural")
    (setq disciplineTrigger (getkword "Select Discipline's Layers to Load: Architectural/Civil/Demolition/Electrical/General\n/Hvac/Instrumentation/Mechanical/Plumbing/Structural: "))
    	(cond 
          ((= disciplineTrigger "Architectural")(prompt (strcat "\nDiscipline Selected: " disciplineTrigger)))
    	  ((= disciplineTrigger "Civil")(prompt (strcat "\nDiscipline Selected: " disciplineTrigger)))
    	  ((= disciplineTrigger "Demolition")(prompt (strcat "\nDiscipline Selected: " disciplineTrigger)))
    	  ((= disciplineTrigger "Electrical")(prompt (strcat "\nDiscipline Selected: " disciplineTrigger)))
    	  ((= disciplineTrigger "General")(prompt (strcat "\nDiscipline Selected: " disciplineTrigger)))
    	  ((= disciplineTrigger "Hvac")(prompt (strcat "\nDiscipline Selected: " disciplineTrigger)))
    	  ((= disciplineTrigger "Instrumentation")(prompt (strcat "\nDiscipline Selected: " disciplineTrigger)))
    	  ((= disciplineTrigger "Mechanical")(prompt (strcat "\nDiscipline Selected: " disciplineTrigger)))
    	  ((= disciplineTrigger "Plumbing")(prompt (strcat "\nDiscipline Selected: " disciplineTrigger)))
    	  ((= disciplineTrigger "Structural")(prompt (strcat "\nDiscipline Selected: " disciplineTrigger)))
    	)
    
    
    ;;;load all the VL commands, then the set the library to Excel 2007 for XP
      (vl-load-com)
      (vl-arx-import)
      (setq tlbfile (findfile "C:\\Program Files\\Microsoft Office\\Office12\\Excel.exe"))
      (setq tlbfile2 (findfile "C:\\Program Files\\Microsoft Office\\Office12\\XL5EN32.OLB"))
      
      (vlax-import-type-library :tlb-filename tlbfile :methods-prefix "msxl-" :properties-prefix "msxl-" :constants-prefix "msxl-") ;Import Libraries
      (vlax-import-type-library :tlb-filename tlbfile :methods-prefix "vlxls-" :properties-prefix "vlxls-" :constants-prefix "vlxls-") ;Import Libraries
       (vlax-import-type-library :tlb-filename tlbfile :methods-prefix "JXCL-" :properties-prefix "JXCL-" :constants-prefix "JXCL-") ;Import Libraries
      
      (vlax-import-type-library :tlb-filename tlbfile2 :methods-prefix "msxl-" :properties-prefix "msxl-" :constants-prefix "msxl-") ;Import Libraries
      (vlax-import-type-library :tlb-filename tlbfile2 :methods-prefix "vlxls-" :properties-prefix "vlxls-" :constants-prefix "vlxls-") ;Import Libraries
    	
    
      ;;;Access Layers in current drawing
      (or *acad* (setq *acad* (vlax-get-acad-object)))
      (or *doc* (setq *doc* (vla-get-activedocument *acad*)))
      (setq layers (vla-get-layers *doc*))
      
    ;;;Open the drawaing issue sheet and find the current worksheet
    (setq xfile "C:\\WORK\\Cadd Spec Customization\\layerS22.xlsx")
      (cond	
        ((setq fn (findfile xfile))
          (cond
            ((setq appsession (vlax-get-or-create-object "Excel.Application"))
              (vlax-invoke-method (vlax-get-property appsession 'workbooks) 'open fn)
              (vla-put-visible appsession 0)
            )
          )
        )
        (t (alert (strcat "nCannot locate source file: " xfile)))
      )
    
    (setq xlapp appsession) ;active session
    
    
    ;Excel Sheets
     (setq Rtn nil)
    	(vlax-for SH (vlax-get-property Xlapp "sheets") 
    	(setq Rtn (cons (vlax-get-property sh "Name") Rtn)) )
    (reverse Rtn)
    (prompt "\n Sheets in file are: \n")
    (princ Rtn)(terpri)
    
    ;shows sheet active
    (prompt "\n Active sheet is: \n")
       (setq shfound (vlax-get-property (msxl-get-ActiveSheet Xlapp) 'name))
    (princ shfound)(terpri)
    
    
    
    (setq mySht (vlax-get-property(vlax-invoke-method Xlapp "Activate")'name))
    
      (setq rng (msxl-get-activesheet xlapp))  			;get active sheet
    
      )

    Attached is the sample Excel File.
    Attached Files Attached Files
    Last edited by freedomonek; 2009-01-19 at 03:26 PM. Reason: make correction

Similar Threads

  1. Making a SelectionSet active in GUI
    By ncraig122139 in forum VBA/COM Interop
    Replies: 7
    Last Post: 2012-03-13, 05:47 PM
  2. Sort() a table in Excel with Vlisp
    By clovis in forum AutoLISP
    Replies: 11
    Last Post: 2007-09-04, 01:48 PM
  3. Excel<->Autocad with vlisp
    By clovis in forum AutoLISP
    Replies: 5
    Last Post: 2007-08-06, 04:02 PM
  4. An active link (Excel OLE)
    By stephen.coff in forum AutoCAD General
    Replies: 11
    Last Post: 2005-11-06, 06:03 PM
  5. Making selected item's workset active
    By narlee in forum Revit - Worksharing/Worksets/Revit Server
    Replies: 5
    Last Post: 2005-06-27, 07:11 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
  •