本文介绍了强制一张桌子适合边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这个问题的答案中建议的代码(
the code suggested in the answer to this question (
如何强制表适合边距?
我尝试过 objDoc.Tables.AutoFitBehavior(wdAutofitWindow)
,但它不起作用。
How can I force the table to fit in the margins?I have tried objDoc.Tables.AutoFitBehavior (wdAutofitWindow)
but it doesn't work.
推荐答案
Sub Export_Click()
Dim objWord As Word.Application
Dim myDoc As Word.Document
Dim myTable As Word.Table
Dim myRange As Excel.Range
Dim lastRow As Long
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set myDoc = objWord.Documents.Add
lastRow = Sheets("export").Range("$G$1").Value 'number of lines to export
Set myRange = Range("A1:F" & lastRow)
myRange.Copy
myDoc.Paragraphs(1).Range.PasteExcelTable _
LinkedToExcel:=False, _
WordFormatting:=False, _
RTF:=False
Set WordTable = myDoc.Tables(1)
WordTable.AutoFitBehavior (wdAutoFitWindow)
Application.CutCopyMode = False 'clear the clipboard
End Sub
此代码基于您的。
对于上述代码,您必须添加 Microsoft Word 12.0对象库的引用。您可以在 VBE
中执行此操作。在工具
菜单中单击参考
并选择 Microsoft Word 12.0对象库
For above code to run you'll have to add reference of Microsoft Word 12.0 Object Library. You can do this in VBE
. In Tools
menu click References
and select Microsoft Word 12.0 Object Library
这篇关于强制一张桌子适合边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!