怎么用vba实现在word中插入excel表格
发布网友
发布时间:2022-05-13 12:13
我来回答
共1个回答
热心网友
时间:2023-10-09 13:04
Sub AA()
Dim projectno As String, projectname As String, datereceive As Date, datecomplate As Date, functionary As String
Dim arr As Object
Dim i As Long
Dim brr
projectno = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1, 2).Range
Dim excelobject As Object
Set excelobject = GetObject("D:\Downloads\project(word)\project.xls")
Set arr = excelobject.Sheets(1).usedrange()
brr = arr
For i = 2 To UBound(brr)
If InStr(1, projectno, brr(i, 1)) > 0 Then
projectname = brr(i, 2)
datereceive = brr(i, 3)
datecomplate = brr(i, 4)
functionary = brr(i, 5)
Exit For
End If
Next i
ActiveDocument.Tables(1).Cell(1, 2).Range = projectname
ActiveDocument.Tables(1).Cell(2, 2).Range = datereceive
ActiveDocument.Tables(1).Cell(3, 2).Range = datecomplate
ActiveDocument.Tables(1).Cell(4, 2).Range = functionary
excelobject.Close False
End Sub