Dim appWord As Word.Application
Dim wrdDoc As Word.Document
Dim strFileName As StringstrFileName = "D:\test\浙江大酒店.doc"
Set appWord = New Word.Application
Set wrdDoc = appWord.Documents.Open(strFileName)'如何读取该文挡中的一行数据'如何修改该行中的数据'如何得到该文本的数据总行和总列数appWord.QuitSet wrdDoc = Nothing
Set appWord = Nothing

解决方案 »

  1.   

    Dim wordObject As Word.Application
    Sub SelectSomeLine()
        Set wordObject = CreateObject("Word.Application")
        wordObject.Visible = True
        wordObject.Documents.Open FileName:="c:\r.doc"    Dim startNum, endNum As Long
        Dim myStartRange, myEndRange As Range    Set myStartRange = wordObject.Selection.GoTo(What:=wdGoToLine,Which:=wdGoToFirst, Count:=10,Name:="")
        Set myEndRange = wordObject.Selection.GoTo(What:=wdGoToLine, Which:=wdGoToFirst, Count:=11, Name:="")
        
        startNum = myStartRange.Start
        endNum = myEndRange.End    MsgBox startNum
        MsgBox endNum
        MsgBox wordObject.Selection.setRange Start := startNum, End := endNum 
    End Sub
      

  2.   

    Private Sub Form_Load()
    '为excel数据的条数
    Dim j As Integer
    j = 0Dim strs As IntegerDim Hotelname As String
    Hotelname = InputBox("请输入你要对帐的酒店名称", "对帐记录", 1000, 1000)
    Screen.MousePointer = 11
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        '打开文挡,并且要准备写入
        Dim appword As New Word.Application
        '复制文件
         Set fs = CreateObject("scripting.filesystemobject")
         fs.CopyFile "d:\test\酒店财务通知模板.doc", "d:\test\" + Hotelname + ".doc"
         appword.Documents.Open ("d:\test\" + Hotelname + ".doc")
         '对文挡进行修改
         Set myrange1 = ActiveDocument.Range(Start:=ActiveDocument.Paragraphs(4).Range.Start, End:=ActiveDocument.Paragraphs(4).Range.End)
         myrange1.Delete
         myrange1.InsertParagraph
         myrange1.InsertBefore ("TO:   " + Hotelname + "         FROM:杭州国太网络服务有限公司")
         Set myrange2 = ActiveDocument.Range(Start:=ActiveDocument.Paragraphs(9).Range.Start, End:=ActiveDocument.Paragraphs(9).Range.End)
         myrange2.Delete
         myrange2.InsertParagraph
         myrange2.InsertBefore ("感谢贵酒店对我公司会员的热情服务及对我公司大力支持,现将2003年" + CStr(Month(Date)) + "月份")
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        '检索出是否有该酒店的记录
        Dim strDestination As String
        Dim xlApp As Excel.Application
        Dim xlbook As Excel.Workbook
        Dim xlsheet As Excel.Worksheet     '激活EXCEL应用程序
        Set xlApp = CreateObject("Excel.Application")
        'EXCEL文件所在路径
        strDestination = "d:\project\国太公司" + "\" + "test.xls"
        '打开工作簿
        Set xlbook = xlApp.Workbooks.Open(strDestination, , False)
        '打开sheet
        Set xlsheet = xlbook.Worksheets(1)
        
        Set myrange3 = ActiveDocument.Range(Start:=ActiveDocument.Paragraphs(10).Range.Start, End:=ActiveDocument.Paragraphs(10).Range.End)
        myrange3.InsertAfter ("      " + CStr(xlsheet.Cells(1, 1)) + "                " + xlsheet.Cells(1, 6) + "                       " + CStr(xlsheet.Cells(1, 8)))
        
        For i = 1 To 100000
            If xlsheet.Cells(i, 4) = "" Then
                Exit For
            End If
            j = j + 1
        Next
        '在excel取数据写入到word中
        For i = 1 To j
            If (xlsheet.Cells(i, 5) = Hotelname And xlsheet.Cells(i, 11) <> "取消") Then
                '把excel内容写入到word中
                Set myrange4 = ActiveDocument.Range(Start:=ActiveDocument.Paragraphs(11).Range.Start, End:=ActiveDocument.Paragraphs(11).Range.End)
                myrange4.InsertAfter (CStr(xlsheet.Cells(i, 1)) + "           " + xlsheet.Cells(i, 6) + "            " + CStr(xlsheet.Cells(i, 8)) + "                               ")
                '取得分子和分母的相乘数
                'strs = xlsheet.Cells(i, 8)
            End If
        Next
        
        Set myrange6 = ActiveDocument.Range(Start:=ActiveDocument.Paragraphs(14).Range.Start, End:=ActiveDocument.Paragraphs(14).Range.End)
        myrange6.Delete
        myrange6.InsertParagraph
        myrange6.InsertBefore ("总共间房: " + "")
        
        'xlApp.Visible = True
        xlbook.Save
         xlApp.Quit
        appword.Visible = True
        ActiveDocument.Save
        appword.Quit
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Screen.MousePointer = 1
    End Sub