|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
代码是X10[1-2位数字上标],自己可以酌情修改
- Sub 复制EXCEL单元格内容到WORD文档()
- '
- ' For WORD/WPS:赋值后再修改上标
- '
- Dim myWord, myDoc As Object
- Dim pos%
- Set myWord = CreateObject("Word.Application")
- myWord.Visible = True
- Set myDoc = myWord.Documents.Open(ThisWorkbook.Path & "\1.doc")
- With myDoc.Tables(1)
- For i = 2 To 5
- .Cell(i, 1).Range.Text = Cells(i, 1)
- .Cell(i, 2).Range.Text = Cells(i, 2)
- Next
- With .Range.Find
- .ClearFormatting
- .Text = "×10[0-9]{1,2}"
- .Wrap = wdFindStop
- .Forward = True
- .MatchWildcards = True
- Do While .Execute
- rStart = .Parent.Start + 3
- rEnd = .Parent.End
- myDoc.Range(rStart, rEnd).Font.Superscript = True
- Loop
- End With
- End With
- Set myDoc = Nothing
- Set myWord = Nothing
- End Sub
复制代码
|
|