在vb中调用word或excel文档,怎样实现?
我需要在程序中通过点击文本连接调用word或者excel文档,请问怎样实现,谢谢!

解决方案 »

  1.   

    什么意思?
    就是打开word , excel 并打开某个文件是吗?1,在project\references 中加入microsoft word 9.0 object library2, 启动word
        Dim wApp As Word.Application
        Set wApp = New Word.Application
        wApp.Visible = True
       关闭word
        wApp.Quit
        Set wApp = Nothing3, 打开文件
        Set wDoc = wapp.Documents.Add  (新建)
        wapp.ActiveDocument.SaveAs Text1.Text (保存)
        Set wDoc = wapp.Documents.Open(FileName:=Text1.Text) (打开指定文件)excel 文件 也可以类似的写
      

  2.   

    shell "winword.exe C:\test.doc"
      

  3.   

    shell "winword.exe C:\test.doc"
      

  4.   

    Private Sub Command3_Click()
        Dim WordApp As New Word.Application
        Dim wDoc As Document
        Dim wTable As Word.Table
        Set wDoc = WordApp.Documents.Open("E:\yours\cdkgood1.doc")       '路径自己选择
        Set wTable = wDoc.Tables(1)     '取第一个表格,这里最好判断一下有没有表格,呵呵
        MsgBox wTable.Cell(1, 1)        '取表的第一行第一列,最好也对行和列作有效判断
        WordApp.Quit                    '这一句是退出
        Set wTable = Nothing
        Set wDoc = Nothing
        Set WordApp = Nothing
    End Sub下面例子复制excel 中第一个sheet复制到同一个excel文件的最后并起名为 my new sheetdim xlSheet as Excel.Worksheet
    dim xlBook  as Excel.WordBook
    dim xlApp   as Excel.Application
    set xlApp = new Excel.Application
    set xlBook = xlApp.WorkBooks.Add("你的excel文件名包括路径")  '打开你要的文件
    xlBook.sheets(1).Activate
    set xlSheet = xlBook.AcitveSheet
    xlSheet.Select
    xlSheet.Copy After:=xlBook.Sheets(xlBook.Sheets.Count)
    set xlSheet = xlBook.ActiveSheet  ’复制Sheet1
    xlSheet.select
    xlSheet.Name = "my new sheet"
    xlSheet.cell(1.2)="Text"    '单元格1行,2列的值为:Text
    xlSheet.range("B3:B4")="Text2" '单元格B3到B4的值为:Text2
    xlApp.Visable = True
    Set xlSheet = nothing
    Set xlBook  = nothing
    Set xlApp = nothing
      

  5.   

    Private Sub Command1_Click()
    Set wrdApp = New Word.Application           '写word文档
    With wrdApp
    'Show Word
    .Visible = True
    'Create New Document
    .Documents.Add
    'Add text to the document
    .ActiveDocument.Content.Text = "Hello"
    .ActiveDocument.Content.Text = "This is a test example"
    .Documents.Save
    End With
    End Sub
      

  6.   

    Private Sub Command2_Click()
     Dim sFileName, sContent, sPartContent As String   '打开word文档并画一个方框
        Dim wrdApp As Object
        Dim k As String
        CommonDialog1.ShowOpen
        If Err <> 0 Then Exit Sub
        sFileName = CommonDialog1.FileName
        If sFileName = "" Then Exit Sub
        Set wrdApp = CreateObject("Word.Application")
        wrdApp.Visible = True
        wrdApp.Documents.Open (sFileName)
        wrdApp.ActiveDocument.Shapes.AddTextbox Orientation:=msoTextOrientationHorizontal, Left:=100, Top:=100, Width:=300, Height:=200
        wrdApp.ActiveDocument.Shapes(1).TextFrame.TextRange = "ee"
        'sContent = wrdApp.ActiveDocument.Content
        wrdApp.Documents.Save
    End Sub
      

  7.   

    引用word好象不太完善哦,万一客户端装的是word2002呢,这是引用microsoft word 9.0 object library不行,要引用microsoft word 10.0 object library,是不是全部都引用全部照顾到,一个机器能同时装word2000,word2002吗?有没有更好的解决方案