下面的代码会复制工作表中的表格并将其粘贴到新的Microsoft Word文档中。唯一的问题是,当粘贴在word文档中时,它会切断一半的表。有什么建议?感谢。
Sub btnExport()
Dim objWord As Word.Application
Range("C2:D60").Copy
Set objWord = CreateObject("Word.Application.14")
With objWord
.Documents.Add
.Visible = True
.Selection.Paste
End With
End Sub
答案 0 :(得分:1)
您可以使用Word AutoFit
命令使表格适合文档。我已经包含了将方向交换为Landscape的代码,但这可能没有必要。
Sub btnExport()
Dim objWord As Word.Application
Range("C2:D60").Copy ' you should name the worksheet as well here really
Set objWord = CreateObject("Word.Application.14")
With objWord
.Documents.Add
.ActiveDocument.PageSetup.Orientation = 1 'wdOrientLandscape
.Visible = True
.Selection.Paste
.ActiveDocument.Tables(1).AutoFitBehavior 2 'wdAutoFitWindow
End With
End Sub