|
原帖由 Saint_Zuo 于 2010-3-16 08:48 发表
不好意思,我对word里的对象元素不太了解。这个66666的位置就是第三次出现“数据”字符串之后与第一次出现句号之间的位置。请教版主您指的那个”链接中的链接“是什么?该如何使用?
只能费劲的揣磨楼主的心思了,累。
以下代码仅供参考。
Option Explicit
Sub Example()
Dim objExcel As Object
Dim objSheet As Object
Dim myRange As Range
Dim myTable As Table
Dim oCell As Cell
Dim vntRange As Variant
Dim strFind As String
Dim xlFileName As String
Dim strXLA1 As String
Dim intCount As Integer
Dim intTarget As Integer
Dim intRow As Integer
Dim intCol As Integer
Dim blnExists As Boolean
strFind = "数据"
intTarget = 3
Selection.HomeKey wdStory
With Selection.Find
.ClearFormatting
.Text = strFind
.Wrap = wdFindStop
.MatchWildcards = False
Do
If .Execute = False Then Exit Sub
intCount = intCount + 1
If intCount = intTarget Then
With ActiveDocument
xlFileName = .Path & "\数据源.xls"
Set myRange = .Range(Selection.End, Selection.Paragraphs(1).Range.End - 1)
Set myTable = .Tables(1)
End With
'''myRange.Select
blnExists = (InStr(myRange.Text, "。") > 0)
If Len(Dir(xlFileName, vbDirectory)) = 0 Then Exit Sub
Set objExcel = GetObject(xlFileName)
Set objSheet = objExcel.sheets(1)
strXLA1 = CStr(objSheet.[A1].Value)
If blnExists = True Then strXLA1 = strXLA1 & "。"
myRange.Text = strXLA1
vntRange = objSheet.[A5:B8].Value
For Each oCell In myTable.Range.Cells
With oCell
intRow = .RowIndex
intCol = .ColumnIndex
.Range.Text = vntRange(intRow, intCol)
End With
Next
Set objExcel = Nothing
Exit Sub
End If
Loop
End With
End Sub |
|