CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  其他开发语言 >  Office开发/ VBA

用VB6操作WORD文档,关闭后再次打开系统会返回错误码462。请问这个问题应该怎么解决?

楼主lxgmag(沧海亦心)2005-05-31 09:20:25 在 其他开发语言 / Office开发/ VBA 提问

出错的函数如下,请各位帮我看一下!  
  Public   Function   funCreatWordDoc(ByRef   aArchive   As   struArchive,   _  
                                                                  ByVal   FileAllPath   As   String)   As   Long  
   
           
            ................  
                   
          Dim   wdApp   As   Object         '   word.Application  
          Set   wdApp   =   CreateObject("word.Application")  
           
          wdApp.Visible   =   False  
          wdApp.Documents.Add             'Err   #5097     内存不足,请现在保存文档  
           
          'Dim   DocName   As   String  
          'DocName   =   wdApp.ActiveDocument.Name  
           
          'Set   wdApp.ActiveDocument.Name   =   "传真公文报"  
           
          'With   ActiveDocument.PageSetup  
           
          '=====   设置纸张及边距  
          With   wdApp.ActiveDocument.PageSetup  
                  'If   .TopMargin   =   72   Then  
                          'pass       'modify   2003.10.26  
                          '.TopMargin   =   50  
                  'Else  
                          .TopMargin   =   CentimetersToPoints(2)                   'TOP   2CM  
                          .BottomMargin   =   CentimetersToPoints(1.8)         'Bottom   1.8cm  
                          .LeftMargin   =   CentimetersToPoints(3.5)             'left       1.5cm  
                          .RightMargin   =   CentimetersToPoints(1.5)           'right     1.5cm  
                          .PageWidth   =   CentimetersToPoints(21)                 'A4纸大小  
                          .PageHeight   =   CentimetersToPoints(29.7)           'A4纸大小  
                  'End   If  
          End   With  
           
          '设置段落行距     ,固定值,28磅   ,左缩进3  
          With   wdApp.Selection.ParagraphFormat  
                  .LineSpacingRule   =   wdLineSpaceExactly  
                  .LineSpacing   =   28  
                  '.CharacterUnitFirstLineIndent   =   3                     报文头以下左缩进3  
                  .Alignment   =   wdAlignParagraphCenter  
          End   With  
           
          '=======       设置公文头格式  
          'wdApp.Selection.ParagraphFormat.Alignment   =   wdAlignParagraphCenter         '中间对齐  
          wdApp.Selection.ParagraphFormat.Alignment   =   wdAlignParagraphJustify               '两端对齐  
          wdApp.Selection.Font.Size   =   26  
          wdApp.Selection.Font.Name   =   "宋体"  
          wdApp.Selection.TypeParagraph  
          wdApp.Selection.TypeParagraph  
          'wdApp.Selection.TypeParagraph  
           
          wdApp.Selection.Font.Size   =   26  
          wdApp.Selection.TypeText   Text:=Space(10)   +   "铁   路   电   报"  
           
          wdApp.Selection.TypeParagraph  
          'wdApp.Selection.Font.Size   =   17  
        '   wdApp.ActiveDocument.Shapes.AddLine(98,   174,   500,   174).Select  
          'wdApp.Selection.Collapse  
          'wdApp.Selection.EndKey   Unit:=wdStory  
          '=======缩短"批示"与线间的间距  
          wdApp.Selection.ParagraphFormat.LineSpacingRule   =   wdLineSpaceExactly  
          wdApp.Selection.ParagraphFormat.LineSpacing   =   18  
           
          '   ===   设置正文  
          wdApp.Selection.TypeText   Text:=vbCrLf  
          wdApp.Selection.ParagraphFormat.CharacterUnitFirstLineIndent   =   0       '左缩进0个字符  
          wdApp.Selection.Font.Size   =   17  
          wdApp.Selection.Font.Name   =   "StarringCS"  
          wdApp.Selection.ParagraphFormat.Alignment   =   wdAlignParagraphJustify               '两端对齐  
          wdApp.Selection.TypeText   Text:="批示:"   +   vbCrLf   +   vbCrLf   +   vbCrLf   +   vbCrLf  
           
          'wdApp.Selection.ParagraphFormat.LineSpacingRule   =   wdLineSpaceExactly  
          'wdApp.Selection.ParagraphFormat.LineSpacing   =   28  
          wdApp.Selection.TypeText   Text:=vbCrLf  
           
          'wdApp.Selection.MoveUp   Unit:=wdLine,   Count:=3  
          wdApp.Selection.Font.Size   =   14  
          wdApp.Selection.TypeText   Text:=aArchive.s报头行   +   vbCrLf   +   vbCrLf  
   
          wdApp.Selection.ParagraphFormat.LineSpacingRule   =   wdLineSpaceExactly  
          wdApp.Selection.ParagraphFormat.LineSpacing   =   28  
          wdApp.Selection.Font.Size   =   17  
          'wdApp.Selection.TypeText   Text:=vbCrLf  
           
          wdApp.ActiveDocument.Shapes.AddLine(100,   150,   500,   150).Select       '报头下第一根线  
          wdApp.ActiveDocument.Shapes.AddLine(100,   241,   500,   241).Select         '报头下第二根线  
          wdApp.ActiveDocument.Shapes.AddLine(100,   278,   500,   278).Select         '报头下第三根线  
          wdApp.Selection.EndKey   Unit:=wdStory  
          Dim   i   As   Long  
          ............          
          'wdApp.ActiveDocument.Shapes.AddLine(100,   150,   500,   150).Select       '报头下第一根线  
          'wdApp.ActiveDocument.Shapes.AddLine(100,   241,   500,   241).Select         '报头下第二根线  
          'wdApp.ActiveDocument.Shapes.AddLine(100,   278,   500,   278).Select         '报头下第三根线  
          'wdApp.ActiveDocument.Shapes.AddLine(100,   750,   500,   750).Select         '画脚注线  
           
          If   Dir(FileAllPath)   <>   ""   Then  
                  Kill   FileAllPath  
          End   If  
          '  
          wdApp.ActiveDocument.SaveAs   FileAllPath  
           
          LSleep   (2.5)  
           
          wdApp.ActiveDocument.Close  
           
          wdApp.Quit  
          Set   wdApp   =   Nothing  
           
         
          'Call   obj1.CloseProcessByExeFileName("WINWORD.EXE")  
          'Set   obj1   =   Nothing  
           
          funCreatWordDoc   =   TotalPage  
           
          Exit   Function         '  
  ErrorHandler:       '   错误处理程序   On   Error   GoTo   ErrorHandler  
           
          Dim   funName   As   String  
          funName   =   cModName   +   "   funCreatWordDoc"  
           
          Dim   ErrNumber,   ErrDescription,   ErrMsg  
          ErrNumber   =   Err.Number  
          ErrDescription   =   Err.Description  
           
          Select   Case   ErrNumber  
              Case   462  
                      wdApp.ActiveDocument.Close  
                      wdApp.Quit  
                      Set   wdApp   =   Nothing  
              Case   482  
                      ErrDescription   =   "打印机错误   "       '不会出现  
                   
          End   Select  
           
          Call   objRunErr.WriteRunErrInfo("99",   funName,   Err.Number,   Err.Description,   gcErrFile)  
           
          'errMsg   =   "Err   #"   +   CStr(ErrNumber)   +   Space(4)   +   ErrDescription   +   Space(6)  
          'MsgBox   errMsg,   vbExclamation,   "错误"  
          Dim   obj1   As   New   SwCommon.clsCloseProcess  
         
          Call   obj1.CloseProcessByExeFileName("WINWORD.EXE")  
           
          Set   obj1   =   Nothing  
  End   Function 问题点数:20、回复次数:3Top

1 楼DawnPine(拂晓的松)回复于 2005-06-06 15:28:57 得分 0

第一次运行能行  
  第二次运行就不行了,是吗?  
   
  会不会是有东西没关闭?Top

2 楼lzlh(lzl)回复于 2005-08-05 20:46:07 得分 10

Dim   wdApp   As   Object         '   word.Application  
          Set   wdApp   =   CreateObject("word.Application")  
  改为:  
          Dim   wdApp   As   new   word.Application  
          Dim   oDoc   As   Word.Document  
   
          Set   oDoc   =   wdApp.Documents.Add  
  使用前绑定   可能要好一些吧Top

3 楼maweifeng(肥嘟嘟左卫门)回复于 2005-08-06 12:22:51 得分 10

前后绑定是一样的,下面最好是这样:  
   
  Set   wdApp   =   Getobject(,   "word.Application")  
  if   wdApp   is   nothing   then  
          Set   wdApp   =   CreateObject("word.Application")  
  end   if  
           
  wdApp.Visible   =   False  
  wdApp.Documents.AddTop

相关问题

  • 有 ORACLE 错误码文档吗? 谢谢大家!
  • 请问有 ORACLE 的错误码 文档吗?倾我所有300分。
  • 请问各位:在输出WORD文档时,进行页面设置一直返回错误码,262。在写代码时应该怎样避免该错误重复出现?
  • oracle 错误码2134
  • 在VB中如何得到SQL SERVER返回的错误码(类似C中的sqlca.sqlcode的东西)?
  • 请问:如何在VB程序中取得存储过程执行的错误码(注意:不是错误信息)。
  • VB中能打开WORD文档吗?
  • VB如何操作WORD文档?
  • 用vb如何打开word文档?
  • 如何在vb种调用word文档?

关键词

  • word
  • wdapp
  • centimeterstopoints
  • errdescription
  • errnumber
  • activedocument
  • funcreatworddoc
  • fileallpath
  • funname
  • err

得分解答快速导航

  • 帖主:lxgmag
  • lzlh
  • maweifeng

相关链接

  • CSDN Blog
  • 技术文档
  • 代码下载
  • 第二书店
  • 读书频道

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo