VBScriptの場合は、変数の型を明示するとコンパイルエラーとなる。
VBAの場合は、変数の型と関数の戻り値を明示的にすること。
また、起点となる処理もモジュール化すること。
'************************************************
'処理:参照フォルダ選択ダイアログの表示
'************************************************
Dim iMsg 'As Integer
Dim strFolder 'As String
strFolder = FnShowFolderDialog()
'判定
If strFolder <> "" Then
iMsg = MsgBox(strFolder & " フォルダの" & vbCrLf & "ファイル取込みを開始します。" & vbCrLf & vbCrLf & "宜しいでしょうか?", vbYesNo, "TITLE")
If iMsg = vbYes Then
'文字列補完
If Right(strFolder, 1) = "\" Then
Else
strFolder = strFolder & "\"
End If
'// 継続する処理を書く
MsgBox "ファイル取込み処理は完了しました", vbInformation
Else
'// iMsg = vbNo ならどうするを書く。
End If
Else
'// キャンセル押下時の処理
End If
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' FunctionName : FnShowFolderDialog
' Function : フォルダ選択ダイアログを表示する。
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function FnShowFolderDialog()' As String
Dim objShell' As Object
Dim objFo ' As Object
Set objShell = CreateObject("Shell.Application")
Set objFo = objShell.BrowseForFolder(0, "フォルダを選択して下さい",&H11)
If objFo Is Nothing Then
FnShowFolderDialog = ""
Else
FnShowFolderDialog = objFo.Items.Item.Path
End If
Set objShell = Nothing
Set objFo = Nothing
End Function