|
楼主 |
发表于 2019-3-18 08:53
|
显示全部楼层
- Sub 生成效果表③()
- 'Date:2019/3/7 二月初一 Thursday
- '标签:word,excel数据导入word
- '备注1:
- Application.DisplayAlerts = False
- ActiveWorkbook.Save
- Application.DisplayAlerts = True
- Dim arr2(1 To 50 ^ 4, 1 To 2), rng As Range
- arr = ActiveWorkbook.ActiveSheet.Range("A1").CurrentRegion
- For i = 3 To UBound(arr)
- If Len(arr(i, 1)) Then
- k = k + 2
- arr2(k, 1) = arr(i, 1)
- End If
- k = k + 1
- arr2(k, 1) = arr(i, 2)
- arr2(k, 2) = arr(i, 3)
- Next
- Application.DisplayAlerts = False
- On Error Resume Next
- ActiveWorkbook.Worksheets("效果表").Delete
- On Error GoTo 0
- With ActiveWorkbook.Worksheets.Add
- .Name = "效果表"
- Columns("a:a").ColumnWidth = 25
- Columns("b:b").ColumnWidth = 70
- [b:b].WrapText = True
- With .Range("A1").Resize(k, 2)
- .Value = arr2
- .EntireColumn.AutoFit
- For Each rng In .Resize(k, 1).SpecialCells(xlCellTypeBlanks)
- With rng.Offset(1).Resize(1, 2)
- .Merge
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- .Font.Bold = True
- .Font.ColorIndex = 3
- .Font.Name = "等线"
- .Font.Size = 16
- End With
- Next
- End With
- .Range("A1").EntireRow.Delete
- .Range("A1").Resize(k - 1, 2).Copy
- End With
- Columns("a:a").ColumnWidth = 19
- Columns("b:b").ColumnWidth = 68
- With CreateObject("Word.Application")
- Set Doc = .Documents.Add
- Doc.Content.PasteExcelTable False, False, False
- Doc.SaveAs2 ActiveWorkbook.Path & "\效果.docx"
- Doc.Close True
- .Quit
- End With
- Set Doc = Nothing
- Application.DisplayAlerts = True
- MsgBox "完成"
- End Sub
复制代码 |
|