外部應用復制 表格 到word中 設置表格自適應


word 批量設置表格寬度自適應

描述 :

我們經常從 外部 如 excel,html 等其他文件 中復制的表格到word 文檔 經常會出現在 word 中顯示不全的問題

主要是源格式的表格 寬度比 word 文檔頁面要大,就會導致 表格無法正常顯示所有數據

 

解決方案

使用 word 宏工具 批量設置 word 文檔中的 表格寬度自適應,即可解決問題!

打開宏編輯器

在當前word文檔中 按 alt + F11 快捷鍵 打開 word 宏編輯器 是 vb 語言。

然后 步驟如下圖 所示

 

 直接上代碼

 附 圖中代碼如下:(盡情的復制吧)

Private Sub Document_Open()
Application.Browser.Target = wdBrowseTable
For i = 1 To ActiveDocument.Tables.Count
    ActiveDocument.Tables(i).AutoFitBehavior (wdAutoFitContent) '根據內容自動調整表格

    ActiveDocument.Tables(i).AutoFitBehavior (wdAutoFitWindow) '根據窗口自動調整表格

    ActiveDocument.Tables(i).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter '水平居中

    ActiveDocument.Tables(i).Range.ParagraphFormat.Alignment = wdCellAlignVerticalCenter '垂直居中

Next i
End Sub

 附代碼如下

注意一定不要忘記 點擊 保存按鈕

方法緣於 博客園大神 傳送門:https://www.cnblogs.com/jiangxin/p/5579885.html

Word 的 宏工具真的有用呀,office 學無止境


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM