|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Sub TEST()
Dim wdApp As Object, wdDoc As Object, ar, i&, strTxt$, f$
Application.ScreenUpdating = False
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err <> 0 Then
Set wdApp = CreateObject("Word.Application")
End If
ar = [B4].CurrentRegion.Value
For i = 2 To UBound(ar)
If Len(ar(i, 1)) Then
If strTxt = "" Then
strTxt = strTxt & ar(i, 1) & "." & ar(i, 2)
Else
strTxt = strTxt & vbCrLf & ar(i, 1) & "." & ar(i, 2)
End If
End If
Next i
f = ThisWorkbook.Path & "\test"
Set wdDoc = wdApp.Documents.Add
With wdDoc
.Content.Text = strTxt
.SaveAs f
.Close
End With
If Err <> 0 Then wdApp.Quit
Set wdApp = Nothing: Set wdDoc = Nothing
Beep
End Sub
|
|