标题:如何关闭进程?例如WINWORD
取消只看楼主
knight24
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2013-6-21
结帖率:50%
 问题点数:0 回复次数:3 
如何关闭进程?例如WINWORD
我利用下面代码可以关闭Opera浏览器进程,有些进程怎么关闭不了??我想关闭WINWORD进程,请教还有什么方法????
    winHwnd = FindWindow(vbNullString, "Opera") '找到窗口Opera浏览器
    Debug.Print winHwnd

    If winHwnd <> 0 Then
    RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&) '关闭窗口
搜索更多相关主题的帖子: 浏览器 Opera 如何 
2013-06-21 15:36
knight24
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2013-6-21
得分:0 
回复 2楼 风吹过b
3Q,我试试!!
2013-06-21 19:54
knight24
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2013-6-21
得分:0 
回复 2楼 风吹过b 再次请教!!
你好!!你提供的方法可以实现!非常感谢。我想实现:如有发现某个其他word文档已经打开,将其进程关闭,只打开我指定word文档进行相关操作。
另外又出现新的问题:利用taskkill 关闭winword.exe后,删除word母版文件后,在“11中 Set doc1 = Documents.Open(outfilepath)这句”出现“远程服务器不存在,462”错误,哪里出问题了呢?能否一看??先谢谢!!
下面是代码:
Dim wordobj As Word.Application
Dim txfilepath As String
Dim outfilepath As String
Dim outputname As String
Dim L As Long
Dim H As Long
Dim H1 As Long
Private Sub Command1_Click()

11
    Set wordobj = New Word.Application

    txfilepath = "E:\图形Word\5f\m1.docx"
    outfilepath = "E:\图形Word\ff\m15.docx"
    FileCopy txfilepath, outfilepath
    L = Text1.Text
    H = Text2.Text
    H1 = Text4.Text
    outputname = "E:\程序开发\图形Word\ff\图.pdf"
    Set doc1 = Documents.Open(outfilepath)
    doc1.Activate
    If Documents.Count < 1 Then
        MsgBox "无文件打开"
    End If
    wordobj.Visible = False
    On Error GoTo ErrHandler
ErrHandler:
   If Err <> 0 Then
      Err.Clear
'##############当发现已经打开了某个其他word文档后修改文本框会报错,需要删除word母版文件###############
    If Dir("C:\Users\knight\AppData\Roaming\Microsoft\Templates\Normal.dot", vbDirectory) <> "" Then
        MsgBox "文件存在"
        Kill "C:\Users\knight\AppData\Roaming\Microsoft\Templates\Normal.dot"
    Else
        MsgBox "文件不存在"
    End If
'
    If Dir("C:\Users\knight\AppData\Roaming\Microsoft\Templates\Normal.dotm", vbDirectory) <> "" Then
      MsgBox "文件存在"
      Shell "taskkill /F /IM " & "winword.exe"
      Kill "C:\Users\knight\AppData\Roaming\Microsoft\Templates\Normal.dotm"
      GoTo 11
    Else
        MsgBox "文件不存在"
       GoTo 11
    End If
   End If
'########################################################
'##################打开指定word文档对指定文本框进行修改#############
    wordobj.ActiveDocument.Shapes("Text Box 22").Select
    wordobj.Selection.ShapeRange.TextFrame.TextRange.Select
    wordobj.Selection.Collapse
    wordobj.Selection.MoveRight Unit:=wdCharacter, Count:=15
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeText Text:=H1
    wordobj.Selection.ShapeRange.TextFrame.TextRange.Select
    wordobj.Selection.Collapse
    wordobj.Selection.ShapeRange.Select
    wordobj.Selection.Collapse
    wordobj.Selection.EscapeKey
    wordobj.Selection.EscapeKey
''''''
    wordobj.ActiveDocument.Shapes("Text Box 24").Select
    wordobj.Selection.ShapeRange.TextFrame.TextRange.Select
    wordobj.Selection.Collapse
    wordobj.Selection.MoveRight Unit:=wdCharacter, Count:=15
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeText Text:=H
    wordobj.Selection.ShapeRange.TextFrame.TextRange.Select
    wordobj.Selection.Collapse
    wordobj.Selection.ShapeRange.Select
    wordobj.Selection.Collapse
    wordobj.Selection.EscapeKey
    wordobj.Selection.EscapeKey
''''''
    wordobj.ActiveDocument.Shapes("Text Box 23").Select
    wordobj.Selection.ShapeRange.TextFrame.TextRange.Select
    wordobj.Selection.Collapse
    wordobj.Selection.MoveRight Unit:=wdCharacter, Count:=15
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeBackspace
    wordobj.Selection.TypeText Text:=L
    wordobj.Selection.ShapeRange.TextFrame.TextRange.Select
    wordobj.Selection.Collapse
    wordobj.Selection.ShapeRange.Select
    wordobj.Selection.Collapse
    wordobj.Selection.EscapeKey
    wordobj.Selection.EscapeKey

'#################另存为PDF格式###############
    wordobj.ActiveDocument.ExportAsFixedFormat OutputFileName:= _
        outputname, ExportFormat:=wdExportFormatPDF, _
        OpenAfterExport:=True, OptimizeFor:=wdExportOptimizeForPrint, Range:= _
        wdExportAllDocument, From:=1, To:=1, Item:=wdExportDocumentContent, _
        IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:= _
        wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:= _
        True, UseISO19005_1:=False
    wordobj.ActiveWindow.Close
    wordobj.Application.Quit
    Set wordobj = Nothing
'    MsgBox "打印完成"
End Sub
2013-06-21 22:07
knight24
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2013-6-21
得分:0 
回复 5楼 风吹过b
是wordobj对象,打开outfilepath = "E:\图形Word\ff\m15.docx"这个word文档。
那么怎么办才能解决关闭word进程后,再次打开word文档不报错呢?
或者提供某种方法,已存在打开的word文档也没关系,不用关闭进程,自动识别你要打开的word文档,然后进行编辑“文本框”文字的操作??请教了!!!我做了一周了,一直没能实现。
2013-06-24 15:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-415721-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.397113 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved