0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Excelマクロでシート別にファイル分割保存する

Posted at

1. はじめに

  • Excelファイルをシート別に分割してExceelファイルに保存したい
  • Excel VBAで一括で処理したい

2. 開発環境

  • Excel for Microsoft 365 (バージョン:2304)
  • Excel VBA

3. 事前準備

  • Excelのオプション> リボンのユーザー設定 で、開発をチェックする
    image.png

  • 開発タブが表示される
    image.png

4. Excelマクロ

Module1.bas
'Excelマクロ
Sub SaveSheet()
    Dim shObj As Worksheet
    Dim newBook As Workbook
    Dim newBookName As String
    Dim folderParent As String
    
    'シートの保存先
    folderParent = ThisWorkbook.Path & "\"
    
    'ワークシート分
    For Each shObj In Worksheets
        
        'シートを新しいブックにコピー
        shObj.Copy
        
        '移動先のブック
        Set newBook = ActiveWorkbook
        
        'シート名
        newBookName = newBook.ActiveSheet.Range("A1") & "_" & shObj.Name & ".xlsx"
        
        '新しいブックを名前を保存
        newBook.SaveAs folderParent & newBookName
        
        '新しいブックを閉じる
        newBook.Close
    
    Next shObj
End Sub

5. 動作確認

5.1. サンプルExcelファイル

image.png

image.png

image.png

5.2. Excelマクロ実行

image.png

image.png

5.3. 実行結果

  • 実行前
    image.png

  • 実行後
    image.png

6. 参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?