Author Topic: add an Validation pulldown to Excel cell  (Read 1389 times)

0 Members and 1 Guest are viewing this topic.

CADwiesel

  • Newt
  • Posts: 46
  • Wir machen das Mögliche unmöglich
add an Validation pulldown to Excel cell
« on: August 30, 2017, 06:28:54 AM »
Hi There,
i'm trying to add an pulldown to an Excel Cell using the Vlisp add methode. The vba code for adding is like this:
Code: [Select]
With Range("e5").Validation
 .Add Type:=xlValidateWholeNumber, _
 AlertStyle:= xlValidAlertStop, _
 Operator:=xlBetween, Formula1:="5", Formula2:="10"
 .InputTitle = "Integers"
 .ErrorTitle = "Integers"
 .InputMessage = "Enter an integer from five to ten"
 .ErrorMessage = "You must enter a number from five to ten"
End With

Now i tried to translate this to VLisp like this:
Code: [Select]
(defun get:active:excel:zells( / excel ExcelWorkbook ExcelSheet ExcelCells zeile spalte)

    (setq   excel (vlax-get-object "excel.application")
            ExcelWorkbook (if excel
                          (vlax-get-property excel "ActiveWorkbook")
                          ) ;_ end of if
            ExcelSheet    (if ExcelWorkbook
                          (vlax-get-property ExcelWorkbook "ACTIVESHEET")
                          ) ;_ end of if
            ExcelCells    (if ExcelSheet
                          (vlax-get-property ExcelSheet "CELLS")
                          ) ;_ end of if
            zeile          3
            spalte         3
            )
  (vl-catch-all-apply
    'vla-add
              (list
                 (vlax-get-property
                   (vlax-variant-value (vlax-get-property ExcelCells "ITEM" zeile spalte)) "Validation")
                 (list "Type" 3);"xlValidateList"
                 (list "AlertStyle" 1);"xlValidAlertStop"
                 (list "Formula1" "Test1;Test2;Test3")
    )
  )
)
  )

But this seems to be wrong. I don't know how to be the Arguments for the ADD Methode. May there is somebody who can help?
Best Regards
CADwiesel
Gruß
CADwiesel
Besucht uns im CHAT

CADwiesel

  • Newt
  • Posts: 46
  • Wir machen das Mögliche unmöglich
Re: add an Validation pulldown to Excel cell
« Reply #1 on: August 30, 2017, 08:04:52 AM »
ok.. i found it. If someone can use it too..

Code: [Select]
(vl-catch-all-apply
    'vla-add
              (list
                 (vlax-get-property
                   (vlax-variant-value (vlax-get-property ExcelCells "ITEM" zeile spalte)) "Validation")
                   (vlax-make-variant 3);xlValidateList
                   (vlax-make-variant 1);xlValidAlertStop
                   (vlax-make-variant 1);Operator
                   (vlax-make-variant "Test1;Test2;Test3");Formula1
                )
  )

Best Regards
CADwiesel
Gruß
CADwiesel
Besucht uns im CHAT

fools

  • Newt
  • Posts: 72
  • China
Re: add an Validation pulldown to Excel cell
« Reply #2 on: August 30, 2017, 09:25:39 AM »
Yes, add "operator" can work.  I tried another way.

Code - Auto/Visual Lisp: [Select]
  1. (DEFUN c:test (/ excel ExcelWorkbook Validation)
  2.   (SETQ excel (VLAX-GET-OBJECT "Excel.Application"))
  3.   (F_LoadTypeLibExecl (VLA-GET-PATH excel)) ;_Type library
  4.   (SETQ ExcelWorkbook (VLAX-GET-PROPERTY excel 'ActiveWorkbook))
  5.   (SETQ Validation (MSXP-GET-VALIDATION (MSXP-GET-RANGE (MSXP-GET-ACTIVESHEET ExcelWorkbook) "c3")))
  6.   (MSXM-ADD Validation MSXC-XLVALIDATELIST MSXC-XLVALIDALERTSTOP MSXC-XLBETWEEN "Test1,Test2,Test3")
  7. )
  8.  
  9. (DEFUN F_LoadTypeLibExecl (ExeclPath / tlbfile)
  10.   (COND ((SETQ tlbfile (FINDFILE (STRCAT ExeclPath "\\Excel8.olb")))) ;_execl97
  11.         ((SETQ tlbfile (FINDFILE (STRCAT ExeclPath "\\Excel9.olb")))) ;_execl2000
  12.         ((SETQ tlbfile (FINDFILE (STRCAT ExeclPath "\\Excel10.olb"))))
  13.         ((SETQ tlbfile (FINDFILE (STRCAT ExeclPath "\\Excel.exe"))))
  14.         (T (SETQ tlbfile nil))
  15.   )
  16.   (IF (AND tlbfile (NULL MSXC-XL24HOURCLOCK))
  17.       :TLB-FILENAME tlbfile :METHODS-PREFIX "msxm-" :PROPERTIES-PREFIX "msxp-" :CONSTANTS-PREFIX "msxc-"
  18.      )
  19.   )
  20. )
Good good study , day day up . Sorry about my Chinglish .