概要
一つ一つの列幅をいちいち指定したくない。
全選択 ⇒ 境界線をダブルクリック のように自動調整したい。
やり方
参照設定に『Microsoft Excel 16.0 Object Library』を追加。
サンプル
Dim excel_ As New Excel.Application
Dim excel_sheet_ As Excel.Worksheet
'バックグラウンドで起動。
excel_.Visible = False
excel_.UserControl = False
'Accessファイルと同じフォルダーにある『tes.xlsx』が対象。
excel_.Workbooks.Open FileName:=CurrentProject.Path & "\tes.xlsx"
'一番左のシートのみを選択状態に。
Set excel_sheet_ = excel_.Worksheets(1)
excel_sheet_.Select Replace:=True
'列幅自動調整。
excel_sheet_.Cells.Columns.AutoFit
'変更保存してエクセルファイル閉じる。
excel_.Workbooks(1).Close SaveChanges:=True
excel_.Quit
バージョン
Windows 10 Pro 22H2 19045.2965
Microsoft Access for Microsoft 365 MSO (バージョン 2304 ビルド 16.0.16327.20200) 32 ビット
Microsoft Excel for Microsoft 365 MSO (バージョン 2304 ビルド 16.0.16327.20200) 32 ビット