求在vb中操作word的源代码,谢谢

解决方案 »

  1.   

    http://www.newasp.net/code/vb/969.html
      

  2.   

    '打开word的操作
    Public oWordApp As Object
    Public oWordres As Object
    Dim WithEvents oWordEvents As Word.ApplicationPrivate Sub OpenWordFile(filename As String)
          
        If filename = "" Then
            Exit Sub
        End If
            
        Set oWordApp = CreateObject("Word.Application")
        If Not oWordApp Is Nothing Then
            If oWordEvents Is Nothing Then
                Set oWordEvents = oWordApp 'Word.Application
            End If
            Set oWordres = oWordApp.Documents.Open(filename, , , False)
            If Not oWordres Is Nothing Then
                        
                oWordApp.Visible = True
                'bringToTop ("Microsoft Word")
                glPid = Shell(appexepath, vbHide)
                bringToTop ("KeyBoard")
            Else
                MsgBox "Could not open the word.", vbCritical
            End If
        Else
            MsgBox "Could not instantiate word.", vbCritical
        End If
        deleteMinMaxButton
        Exit Sub
       
        
    openwordend:
        
        MsgBox "File not find!" & Chr(13) & "Please consult administrator! " & Err.Description
       
    End SubPrivate Sub oWordEvents_Quit()
        cmdKill
        oWordApp.Quit
        Set oWordApp = Nothing
        Set oWordres = Nothing
        Set oWordEvents = Nothing
        
    End Sub
      

  3.   

    如果你是连接到WORD对象,那给你个建议,想实现相应操作的时候将你的操作录制成宏,然后查看宏代码,在VB里如何写就一目了然了