|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Sub TEST()
Dim xlApp As Object, Items As FileDialogSelectedItems, strPath$
Dim ar, br, i&, j&, r&, strJoin$
strPath = ThisDocument.Path & "\"
With Application.FileDialog(1)
With .Filters
.Clear
.Add "Word文档(doc?)", "*.xls"
End With
.AllowMultiSelect = False
.InitialFileName = strPath
If .Show Then Set Items = .SelectedItems Else Exit Sub
End With
'
Application.ScreenUpdating = False
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err <> 0 Then
Set xlApp = CreateObject("Excel.Application")
End If
With xlApp.Workbooks.Open(Items(1))
With .Sheets(1)
r = .Cells(.Rows.Count, "A").End(xlUp).Row
ar = .Range("A5:i" & r).Value
ReDim br(1 To UBound(ar) - 1)
For i = 2 To UBound(ar)
strJoin = ""
For j = 2 To UBound(ar, 2)
If InStr(ar(1, j), "率") Then
strJoin = strJoin & "," & ar(1, j) & Format(ar(i, j), "0.00%")
Else
strJoin = strJoin & "," & ar(1, j) & ar(i, j)
End If
Next j
br(i - 1) = ar(i, 1) & " " & Mid(strJoin, 2)
Next i
End With
.Close False
End With
ActiveDocument.Content.Text = Join(br, vbCr)
If Err <> 0 Then xlApp.Quit
Set xlApp = Nothing
Set Items = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|
评分
-
1
查看全部评分
-
|