hszhxl 发表于 2009-1-2 21:56:00

求教:如何用VLISP保存并关闭EXCEL

<p>请问如何让VLISP控制EXCEL保存后关闭?因为我用VLISP向EXCEL中写入了数据,然后关闭EXCEL,跳出对话框提示是否保存,如何让VLISP自动完成保存并退出的过程?</p>

tony911 发表于 2009-2-4 17:08:00

<p>俺也想知道</p>

hszhxl 发表于 2009-2-11 09:59:00

本帖最后由 作者 于 2009-2-12 11:56:51 编辑 <br /><br /> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;">首先再次感谢明经通道,让我学到了太多的<font face="Times New Roman">LISP</font>相关知识,尤其是<a href="http://www.mjtd.com/a2/list.asp?id=348">http://www.mjtd.com/a2/list.asp?id=348</a>对我的帮助最大。在使用本贴过程中,我发现<font face="Times New Roman">Figure 1</font>和示例<font face="Times New Roman">7</font>做如下调整似乎更好:</p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><p><font face="Times New Roman">&nbsp;</font></p></p><p><font face="Times New Roman">&nbsp;</font></p><p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">;;;<span style="mso-spacerun: yes;">&nbsp; 1</font></span>、加载<font face="Times New Roman">EXCEL</font>类型库,已修改为直接寻找<font face="Times New Roman">EXCEL</font>的安装路径,支持<font face="Times New Roman">EXCEL97</font>、<font face="Times New Roman">2000</font>、<font face="Times New Roman">2002</font>、<font face="Times New Roman">2003</font>、<font face="Times New Roman">2007</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">;;;<span style="mso-spacerun: yes;">&nbsp; </font></span>注:<font face="Times New Roman">OFFICE97</font>为<font face="Times New Roman">Excel8.olb</font>,<font face="Times New Roman">OFFICE2000</font>为<font face="Times New Roman">Excel9.olb </font>,<font face="Times New Roman">OFFICE2002</font>为<font face="Times New Roman">Excel10.olb</font>,之后的版本均为<font face="Times New Roman">Excel.exe</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">;;;<span style="mso-spacerun: yes;">&nbsp; </font></span>修改原因:当<font face="Times New Roman">EXCEL</font>安装路径不在<font face="Times New Roman">C</font>盘或不是默认路径时,原程序调用失败。</p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="宋体">(defun DSX-TypeLib-Excel (/ path tlb)<br/>&nbsp; (if (setq obj (vlax-create-object "Excel.Application"))<br/>&nbsp;&nbsp;&nbsp; (progn<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq path (vlax-get-property obj 'Path))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (cond<br/>&nbsp;((setq<br/>&nbsp;&nbsp;&nbsp; tlb (findfile<br/>&nbsp;&nbsp; (strcat<br/>&nbsp;&nbsp;&nbsp;&nbsp; path<br/>&nbsp;&nbsp;&nbsp;&nbsp; "<a href="file://\\Excel8.olb">\\Excel8.olb</a>"<br/>&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp; )<br/>&nbsp; tlb<br/>&nbsp;)<br/>&nbsp;((setq<br/>&nbsp;&nbsp;&nbsp; tlb (findfile<br/>&nbsp;&nbsp; (strcat<br/>&nbsp;&nbsp;&nbsp;&nbsp; path<br/>&nbsp;&nbsp;&nbsp;&nbsp; "<a href="file://\\Excel9.olb">\\Excel9.olb</a>"<br/>&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp; )<br/>&nbsp; tlb<br/>&nbsp;)<br/>&nbsp;((setq tlb<br/>&nbsp;&nbsp;(findfile<br/>&nbsp;&nbsp;&nbsp; (strcat<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; path<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "<a href="file://\\Excel10.olb">\\Excel10.olb</a>"<br/>&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;)<br/>&nbsp; )<br/>&nbsp; tlb<br/>&nbsp;)<br/>&nbsp;((setq<br/>&nbsp;&nbsp;&nbsp; tlb (findfile<br/>&nbsp;&nbsp; (strcat<br/>&nbsp;&nbsp;&nbsp;&nbsp; path<br/>&nbsp;&nbsp;&nbsp;&nbsp; "<a href="file://\\Excel.exe">\\Excel.exe</a>"<br/>&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp; )<br/>&nbsp; tlb<br/>&nbsp;)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp; (alert<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "本系统内未发现已安装的 EXCEL97、2000、2002、2003、2007,初始化失败!"<br/>&nbsp;&nbsp;&nbsp; )<br/>&nbsp; )<br/>)</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman"></font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;">参照:<a href="http://bbs.mjtd.com/forum.php?mod=viewthread&tid=59763"><font face="Times New Roman">http://bbs.mjtd.com/forum.php?mod=viewthread&tid=59763</font></a></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><p><font face="Times New Roman">&nbsp;</font></p></p><p><font face="Times New Roman">&nbsp;</font></p><p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><p><font face="Times New Roman">&nbsp;</font></p></p><p><font face="Times New Roman">&nbsp;</font></p><p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;">示例<font face="Times New Roman">7</font>:</p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;">将第二行的<font face="Times New Roman">msxl-put-value</font>改为<font face="Times New Roman">msxl-put-value2</font>,解决在<font face="Times New Roman">EXCEL2003</font>和<font face="Times New Roman">2007</font>中写入失败的问题。</p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;">注:因为本人一直使用<font face="Times New Roman">EXCEL2003</font>和<font face="Times New Roman">2007</font>,不知在<font face="Times New Roman">EXCEL</font>老版本中是否正常。</p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;">参照:<a href="http://www.mjtd.com/bbs/Archive_view.asp?boardID=3&amp;ID=39367"><font face="Times New Roman">http://www.mjtd.com/bbs/Archive_view.asp?boardID=3&amp;ID=39367</font></a></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><p><font face="Times New Roman">&nbsp;</font></p></p><p><font face="Times New Roman">&nbsp;</font></p><p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;">取之于明,用之于明!</p>

hszhxl 发表于 2009-2-11 10:00:00

<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;">另外,还请各位大侠帮忙解决我在1楼提到的问题,直到今天我还没有解决,盼!</p>

yshf 发表于 2009-2-11 15:03:00

本帖最后由 作者 于 2009-2-11 15:04:04 编辑 <br /><br /> <p>将"DisplayAlerts"属性值设为False,即</p><p>(vlax-put-property ExcelAPP "DisplayAlerts" :vlax-False)</p><p>然后再退出Excel。</p><p></p>

hszhxl 发表于 2009-2-12 11:58:00

<strong><font face="Verdana" color="#61b713">非常感谢yshf,问题已解决!</font></strong>
页: [1]
查看完整版本: 求教:如何用VLISP保存并关闭EXCEL