Option Explicit
Option Base 1
'==================================================
' モジュール名: Mod_ExportFile
' 概要: CSVファイルのエクスポート機能を提供するモジュール
' 主な機能: 出力先パス取得、CSVファイル書き出し
'==================================================
'--------------------------------------------------
'--------------------------------------------------
Sub exportCsvFile()
Dim strExpFolder As String
Dim strExpFileName As String
If blnGetOutPath = False Then Exit Sub
lblErr:
MsgBox "ファイル出力処理中にエラーが発生しました。" & vbCrLf & _
"エラー番号: " & Err.Number & vbCrLf & _
"内容: " & Err.Description, vbExclamation, "onClickImportFile"
End Sub
'--------------------------------------------------
'プロシージャの概要:
'処理名: blnGetOutPath
'概要: メインシートから出力フォルダパスおよびファイル名を取得
' 出力フォルダが存在しない場合は作成する
'引数リスト
'strFolder: 出力フォルダパス格納用変数
'strFile : 出力ファイル名格納用変数
'戻り値: Boolean: フォルダが存在または作成成功した場合はTrue、作成失敗時はFalse
'--------------------------------------------------
Private Function blnGetExpotPath(ByRef strFolder As String, ByRef strFile As String) As Boolean
On Error GoTo lblErr
' 出力フォルダパスを取得
strFolder = shMain.Cells(ROW_shMAIN_EXPORTPATH, COL_shMAIN_EXPORTFOLDER).Value
' 出力ファイル名を取得
strFile = shMain.Cells(ROW_shMAIN_EXPORTPATH, COL_shMAIN_EXPORTFILE).Value
' フォルダが存在しない場合は作成する
If Dir(strFolder, vbDirectory) = "" Then
MkDir strFolder
End If
blnGetOutPath = True
Exit Function
lblErr:
MsgBox "出力フォルダの作成に失敗しました。" & vbCrLf & _
"フォルダ: " & strFolder, vbExclamation, "blnGetOutPath"
blnGetOutPath = False
End Function
コメント