Option Explicit 'ファイルメニューに対応するコマンド '「新規作成」 Public Sub CrateDataFile() Dim clsFile As clsFiles If gstrName <> "" Then GoTo ErrorProc 'ファイルクラスのインスタンス Set clsFile = New clsFiles clsFile.AddWorkBook gstrName = clsFile.Name Set clsFile = Nothing If gstrName = "" Then Exit Sub gFlg = False MsgBox "続けて、事業所名を設定します。", 64 + 0, "給与計算システム" frmCorp.Show If gFlg = True Then GoTo ErrorExit gFlg = False MsgBox "続けて、健康保険、雇用保険の設定をします。", 64 + 0, "給与計算システム" frmKoyou.Show If gFlg = True Then GoTo ErrorExit gFlg = False MsgBox "最後に会計年度の設定をします。", 64 + 0, "給与計算システム" frmNendo.Show If gFlg = True Then GoTo ErrorExit 'EXCELのタイトルバーにデータファイル名を表示 Application.Caption = "給与計算システム for Microsoft Excel" & Chr(32) & "-" & Chr(32) & gstrName gFlg = True Exit Sub ErrorProc: MsgBox "すでにデータファイルが開いています。", 16 + 0, "給与計算システム" ErrorExit: MsgBox "作業を中止しました。" & vbCrLf & "データファイルが正しく作成されませんでした。", 64 + 0, "給与計算システム" Workbooks(gstrName).Close False gstrName = "" End Sub '「開く」 Public Sub OpenDataFile() Dim clsFile As clsFiles 'エラートラップ If gstrName <> "" Then GoTo FilesErrorProc 'ファイルクラスのインスタンス Set clsFile = New clsFiles clsFile.OpenWorkBook gstrName = clsFile.Name 'EXCELのタイトルバーにデータファイル名を表示 Application.Caption = "給与計算システム for Microsoft Excel" & Chr(32) & "-" & Chr(32) & gstrName Set clsFile = Nothing Exit Sub FilesErrorProc: MsgBox "すでにデータファイルが開いています。", 16 + 0, "給与計算システム" End Sub '「閉じる」 Public Sub CloseDataFile() Dim clsFile As clsFiles Dim intMsg As Integer 'メッセージの戻り値 'エラートラップ If gstrName = "" Then GoTo FilesErrorProc intMsg = MsgBox("データファイルを閉じます。", 64 + 0, "給与計算システム") 'ファイルクラスのインスタンス Set clsFile = New clsFiles clsFile.Name = gstrName clsFile.CloseWorkBook gstrName = "" 'EXCELのタイトルバーを戻す Application.Caption = "給与計算システム for Microsoft Excel" Set clsFile = Nothing Exit Sub FilesErrorProc: MsgBox "データファイルが開いていないか、または、壊れています。", 16 + 0, "給与計算システム" End Sub '「名を付けて保存」 Public Sub RenameDataFile() Dim clsFile As clsFiles 'エラートラップ If gstrName = "" Then GoTo FilesErrorProc 'ファイルクラスのインスタンス Set clsFile = New clsFiles clsFile.Name = gstrName clsFile.RenameWorkBook Set clsFile = Nothing Exit Sub FilesErrorProc: MsgBox "データファイルが開いていないか、または、壊れています。", 16 + 0, "給与計算システム" End Sub '「上書き保存」 Public Sub SaveDataFile() Dim clsFile As clsFiles 'エラートラップ If gstrName = "" Then GoTo FilesErrorProc 'ファイルクラスのインスタンス Set clsFile = New clsFiles clsFile.Name = gstrName clsFile.SaveWorkbook Set clsFile = Nothing Exit Sub FilesErrorProc: MsgBox "データファイルが開いていないか、または、壊れています。", 16 + 0, "給与計算システム" End Sub '年度更新 Public Sub Kousin() 'エラートラップ If gstrName = "" Then GoTo FilesErrorProc gFlg = True frmNendo.Show Exit Sub FilesErrorProc: MsgBox "データファイルが開いていないか、または、壊れています。", 16 + 0, "給与計算システム" End Sub 'ファイル分割 Public Sub Bunkatu() Dim clsBunkatu As clsDivision 'ファイル分割クラス 'エラートラップ If gstrName = "" Then GoTo FilesErrorProc 'クラスのインスタンス Set clsBunkatu = New clsDivision clsBunkatu.StartDivision 'EXCELのタイトルバーにデータファイル名を表示 Application.Caption = "給与計算システム for Microsoft Excel" & Chr(32) & "-" & Chr(32) & gstrName Exit Sub FilesErrorProc: MsgBox "データファイルが開いていないか、または、壊れています。", 16 + 0, "給与計算システム" End Sub