现在的位置: 首页 > 综合 > 正文

vba excel to word

2013年06月13日 ⁄ 综合 ⁄ 共 534字 ⁄ 字号 评论关闭

将excel中的数据按表格形式保存到word中:(在“工具”菜单中选中"引用"项 )

选择: MicroSoft Word 11.0 Object Libarary

代码:

Public Sub ExportWord()
    Dim WordApp As Word.Application
    Set WordApp = CreateObject("Word.Application")
    WordApp.Visible = True
    With WordApp
        Set newDoc = .Documents.Add
        With .Selection
            For Each C In Worksheets("Sheet1").Range("A1:B10")
                .InsertAfter Text:=C.Value
                Count = Count + 1
                If Count Mod 2 = 0 Then
                    .InsertAfter Text:=vbCr
                Else
                    .InsertAfter Text:=vbTab
                End If
            Next
            .Range.ConvertToTable Separator:=wdSeparateByTabs
            .Tables(1).AutoFormat Format:=wdTableFormatClassic1
        End With
    End With
    Set WordApp = Nothing
            
End Sub

抱歉!评论已关闭.