VBA 將Excel活頁簿中所有表格進行一鍵排版

來源:互聯網
上載者:User

標籤:一鍵   需要   lines   als   一鍵排版   indent   排版   迴圈   str   

自己管理的Excel活頁簿經過多人的修改,其中的很多格式會經常出現不一致的情況,這裡提供VBA代碼,用來實現表格式資料格式一鍵排版,免除手動頻繁調整Excel資料格式。

 1 Option Explicit 2 Option Base 1 3  4 Sub autoSet() 5     Dim i As Integer 6      7     For i = 1 To Sheets.Count 8         Sheets(i).Activate      ‘這行代碼不能省,再進行表格操作前,需要先啟用需要操作的表格 9         Sheets(i).Cells.Select10         With Selection.Font11             .Name = "微軟雅黑"    ‘設定字型種類12             .Size = 11        ‘設定字型大小13             .Strikethrough = False14             .Superscript = False15             .Subscript = False16             .OutlineFont = False17             .Shadow = False18             .Underline = xlUnderlineStyleNone19             .TintAndShade = 020             .ThemeFont = xlThemeFontNone21         End With22         With Selection23             .HorizontalAlignment = xlLeft  ‘設定文本排列,靠左24             .VerticalAlignment = xlCenter  ‘設定文本排列,垂直置中25             .Orientation = 026             .AddIndent = False27             .IndentLevel = 028             .ShrinkToFit = False29             .ReadingOrder = xlContext30             .MergeCells = False31         End With32         Sheets(i).Range("A1").Select33     Next34 End Sub

需要設定其他方面的格式,直接在for迴圈內添加相應代碼即可實現,可以先錄製宏來查看設定的代碼,再進行添加

VBA 將Excel活頁簿中所有表格進行一鍵排版

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.