怎么样在vb 中以VBMODAL的方式来显示EXCEL或WORD对象。这样可以控制好EXCEL或WORD对象的释放。

解决方案 »

  1.   

    下面是一个打开指定Word文档并等待其被关闭的代码,自己改改吧。
    Public Function ShowProcess(FileName As String, ByVal OwnerhWnd As Long, Optional ByVal strCmd As String = "open") As Long
        Dim SEI As SHELLEXECUTEINFO
        Dim r As Long
        With SEI
            'Set the structure's size
            .cbSize = Len(SEI)
            'Set the mask
            .fMask = SEE_MASK_FLAG_DDEWAIT Or SEE_MASK_NOCLOSEPROCESS
            'Set the owner window
            .hwnd = OwnerhWnd
            'Show the properties
            .lpVerb = strCmd '"open" '"properties"
            'Set the filename
            .lpFile = FileName
            .lpParameters = vbNullChar
            .lpDirectory = vbNullChar
            .nShow = SW_SHOWMAXIMIZED
            .hInstApp = 0
            .lpIDList = 0
        End With
        r = ShellExecuteEx(SEI)
        If r Then
            ShowProcess = SEI.hProcess
        End If
    End FunctionPublic Function WaitModifyTaskDocument(ByRef strTFn As String) As Boolean
    On Error GoTo ErrDeal
        Dim lngHProcess As Long, lngReturn As Long
        Dim blnR As Boolean
        
        lngHProcess = ShowProcess(strTFn, 0)
        If lngHProcess <> 0 Then
            lngReturn = WaitForSingleObject(lngHProcess, INFINITE)
            If lngReturn <> csWAIT_OBJECT_0 Then
                SetLastErrorEx "&micro;&Egrave;&acute;&yacute;&Oacute;&Atilde;&raquo;§&Ocirc;&Auml;&para;&Aacute;" & csTASKNOTEMESSAGE & "&acute;í&Icirc;ó&pound;&iexcl;"
                GoTo ErrDeal
            End If
            blnR = CBool(TerminateProcess(lngHProcess, 0))
            
            'John 2002-03-29
            'in windows98 ev the terminateprocess function return true value
            'but in winnt or window2000 ev the terminateprocess function return false value
            'so set the blnr = true
            blnR = True
        End If
        
        WaitModifyTaskDocument = blnR
        
    ErrDeal:
        Select Case Err.Number
        Case 0
        Case Else
            SetLastErrorEx Err.Description
        End Select
    End Function