1.根据窗口标题来FindWindow(...),取得窗口句柄
2.sendmessage(WM_CLOSE,.....)

解决方案 »

  1.   

    但是我调用api出错,提示:ACTIVE X不能。或者是不能建立API函数的入口。
    有时间,给个例子好吗?谢谢!!
      

  2.   

    这应该不是api本身的问题,我们这里很多这种情况,都按书上照抄了还是出这样的错.
      

  3.   

    最好是去看一下MSDN 上的參數設置,不過同時在運行是要SAVE一下喲,要不很可能就沒了!
      

  4.   

    同意 whoke(hy)应该没有问题,是不是系统的问题
      

  5.   


    Dim objword as word.application
    Dim objDoc as word.Documentprivate sub cmdStart_click()
            'Start Word and make it visible
         set objWord=New word.Application
         objWord.visuble=True
         
         'Create a new document
         set objDoc=objWord.Documents.Add 
            '打开一个已有的文档
        'Set objDoc=objWord.Documents.Open("C:\Temp\Luqingming.Doc") 
         
         
        'Make it activate document
         objDoc.Activate End Sub
    private Sub cmdClose_click()
         
         'Close word without saving changes 
         objWord.Quit False  '如果你使用 objDoc.Close False 则只关闭文档
         'Destroy object reference
          set objWord=NothingEnd Sub
    本程序只有一个框架,没有出错处理,还需你自己完善。
      

  6.   

    关闭打开指定路径的windows窗口在一个模块文件中写入以下代号:
    Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
      (Byval IpClassName As String,Byval IpWindowName as STring) as Long
    '你还需在此加入一个SendMessage  API'IpClassName 是窗口的类型;  IpWindowName 是窗口的标题Sub TestCloseWindow(Byval sWindowCaption as String)    dim hwndCurrent as Long  '定义一个窗口句柄
        dim lClose as Long
        hwndCurrent=FindWindow(vbNullString,sWindowCaption)
        
        if hwndCurrnt=0
          msgbox “你指定的” & sWindowCaption "窗口没有打开"
          exit sub
        else
         lClose=SentMessage(hwndCurrent,WM_CLOSE,0&,0&)
        endifend sub