概要
やり方
参照設定に『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
'1行3列目(C1セル)に対して設定。
'選択した時に『1.88E+08』のようにならないよう、セルは文字列にしておいた方がいい。
excel_sheet_.Cells(1, 3).NumberFormatLocal = "@"
'既に入力規則が設定されていた場合、それが悪影響しないように一旦削除をかませる。
excel_sheet_.Cells(1, 3).Validation.Delete
'入力規則設定。
excel_sheet_.Cells(1, 3).Validation.Add Type:=xlValidateList, Operator:=xlEqual, Formula1:="あ,い,う"
'変更保存してエクセルファイル閉じる。
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 ビット