明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 8760|回复: 5

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

[复制链接]
发表于 2011-10-27 15:37:10 | 显示全部楼层 |阅读模式
(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。
谢谢啦!
发表于 2011-10-28 15:40:36 | 显示全部楼层
(vla-put-visible Xlobj 1)
这一句执行的时候,xlobj的值还是nill

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

还有,有个“)”的位置错了
 楼主| 发表于 2011-10-29 09:23:10 | 显示全部楼层
lazybug 发表于 2011-10-28 15:40
(vla-put-visible Xlobj 1)
这一句执行的时候,xlobj的值还是nill

请问怎么将MX-acos赋值?还有那个Xlobj不需要赋值吧?谢谢了,我刚开始学习,不大懂
发表于 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、其余如下:

  1. (defun C:sjk()
  2.   
  3.   (vl-load-com)
  4.   
  5.   (if (not (findfile (setq exlib "C:\\Program files\\Microsoft office\\Office12\\Excel.exe")))
  6.       (if (not (findfile (setq exlib "C:\\Program files\\Microsoft office\\Office10\\Excel.exe")))
  7.           (if (not (findfile (setq exlib "C:\\Program files\\Microsoft office\\Office11\\Excel.exe")))
  8.               (vl-exit-with-error "不能引入Excel类型库!")
  9.           )
  10.       )
  11.   )

  12.   (if(null MX-acos)
  13.      (vlax-import-type-library
  14.            :tlb-filename         exlib
  15.            :methods-prefix       "MX-"
  16.            :properties-prefix    "MX-"
  17.            :constants-prefix     "MX-"
  18.      )
  19.    
  20.    )

  21.    (setq XLobj (vlax-create-object "Excel.Application"))
  22.    (vla-put-visible Xlobj :vlax-true)
  23.    (vlax-invoke-Method(vlax-get-Property XLobj'Workbooks)'Open filename)
  24.    (setq filename"f:\\1.xls")
  25.    (setq sheetobj(MX-get-activesheet XLobj))
  26.    (setq cells(MX-get-cells sheetobj))
  27.    (setq cell-1-2 (vlax-variant-value(MX-get-value-sheetobj-1-2)))
  28.    (princ"\nCELL-1-2=")(princ cell-1-2)
  29.    (vlax-invoke-method XLobj 'QUIT)
  30.    (vlax-release-object XLobj)
  31.    (setq XLobj nil)
  32.    (princ)
  33. )


 楼主| 发表于 2011-10-29 15:52:49 | 显示全部楼层
yshf 发表于 2011-10-29 12:31
1、 (vla-put-visible Xlobj 1) 的一行右括号是多余的
2、将 (vla-put-visible Xlobj 1) 移动到 (setq XLo ...

谢谢了!
发表于 2013-5-14 10:08:35 | 显示全部楼层
又学了一手,谢谢了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-30 07:36 , Processed in 0.153024 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表