|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
附件,打开word文档,点击按钮》》》》》》》- Private Sub CommandButton1_Click()
- Dim cx As New ADO, sql$, pf$, f$, str$, ostr$
- Application.ScreenUpdating = False
- pf = ThisDocument.Path & "\Test1.xlsx"
- str = Replace(Split(Trim(ActiveDocument.Paragraphs(1).Range), "]")(0), "[", "")
- sql = "select 公司名称 from [" & pf & "].[sheet1$] where 编号='" & str & "'"
- arr = cx.Sqlist(pf, sql)
- For j = 0 To UBound(arr, 2)
- For i = 0 To UBound(arr)
- If i = 0 Then
- s = arr(i, j)
- Else
- s = s & vbTab & arr(i, j)
- End If
- Next
- ostr = ostr & s & vbCr
- Next
- With ActiveDocument.Content
- .MoveStart 4, 1: .Delete: .Text = vbCr: .Text = ostr
- .ConvertToTable 1, UBound(arr, 2) + 1, UBound(arr) + 1
- .Tables(1).Style = "网格型"
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码
|
|