cnsdjnzc 发表于 2011-10-27 15:37:10

(求助)程序运行过程中总是出现错误:参数类型错误:VLA-OBJECT nil

(defun C:sjk()

(vl-load-com)

(setq exlib "C:Program files\\Microsoft office\\Office12\\Excel.exe")
(setq exlib "C:Program files\\Microsoft office\\Office10\\Excel.exe")
(setq exlib "C:Program files\\Microsoft office\\Office11\\Excel.exe")
(vla-put-visible Xlobj 1)
)
(if(null MX-acos)
   (vlax-import-type-library
         :tlb-filename         exlib
    :methods-prefix       "MX-"
    :properties-prefix    "MX-"
   
    :constants-prefix   "MX-"
   )
   
   )


(setq XLobj(vlax-create-object"Excel.Application"))
   

(vlax-invoke-Method(vlax-get-Property XLobj'Workbooks)'Open filename)
(setq filename"f:\\1.xls")
(setq sheetobj(MX-get-activesheet XLobj))
(setq cells(MX-get-cells sheetobj))

(setq cell-1-2 (vlax-variant-value(MX-get-value-sheetobj-1-2)))

(princ"\nCELL-1-2=")(princ cell-1-2)
(vlax-invoke-method XLobj 'QUIT)
(vlax-release-object XLobj)
(setq XLobj nil)
)
大家帮忙看一下这个程序哪个地方需要修改,运行过程中总是出现错误:参数类型错误:VLA-OBJECT nil。
谢谢啦!

lazybug 发表于 2011-10-28 15:40:36

(vla-put-visible Xlobj 1)
这一句执行的时候,xlobj的值还是nill

还有这句(if(null MX-acos)
也是没赋值就引用参数了

还有,有个“)”的位置错了

cnsdjnzc 发表于 2011-10-29 09:23:10

lazybug 发表于 2011-10-28 15:40 static/image/common/back.gif
(vla-put-visible Xlobj 1)
这一句执行的时候,xlobj的值还是nill



请问怎么将MX-acos赋值?还有那个Xlobj不需要赋值吧?谢谢了,我刚开始学习,不大懂

yshf 发表于 2011-10-29 12:31:41

本帖最后由 yshf 于 2011-10-29 12:35 编辑

1、 (vla-put-visible Xlobj 1) 的一行右括号是多余的
2、将 (vla-put-visible Xlobj 1) 移动到 (setq XLobj(vlax-create-object"Excel.Application"))行的下面一行
3、其余如下:

(defun C:sjk()

(vl-load-com)

(if (not (findfile (setq exlib "C:\\Program files\\Microsoft office\\Office12\\Excel.exe")))
      (if (not (findfile (setq exlib "C:\\Program files\\Microsoft office\\Office10\\Excel.exe")))
          (if (not (findfile (setq exlib "C:\\Program files\\Microsoft office\\Office11\\Excel.exe")))
            (vl-exit-with-error "不能引入Excel类型库!")
          )
      )
)

(if(null MX-acos)
   (vlax-import-type-library
         :tlb-filename         exlib
         :methods-prefix       "MX-"
         :properties-prefix    "MX-"
         :constants-prefix   "MX-"
   )
   
   )

   (setq XLobj (vlax-create-object "Excel.Application"))
   (vla-put-visible Xlobj :vlax-true)
   (vlax-invoke-Method(vlax-get-Property XLobj'Workbooks)'Open filename)
   (setq filename"f:\\1.xls")
   (setq sheetobj(MX-get-activesheet XLobj))
   (setq cells(MX-get-cells sheetobj))
   (setq cell-1-2 (vlax-variant-value(MX-get-value-sheetobj-1-2)))
   (princ"\nCELL-1-2=")(princ cell-1-2)
   (vlax-invoke-method XLobj 'QUIT)
   (vlax-release-object XLobj)
   (setq XLobj nil)
   (princ)
)


cnsdjnzc 发表于 2011-10-29 15:52:49

yshf 发表于 2011-10-29 12:31 static/image/common/back.gif
1、 (vla-put-visible Xlobj 1) 的一行右括号是多余的
2、将 (vla-put-visible Xlobj 1) 移动到 (setq XLo ...

谢谢了!

shiyan001 发表于 2013-5-14 10:08:35

又学了一手,谢谢了
页: [1]
查看完整版本: (求助)程序运行过程中总是出现错误:参数类型错误:VLA-OBJECT nil