Skip to content

Instantly share code, notes, and snippets.

@nobrinskii
Created October 19, 2012 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobrinskii/3917476 to your computer and use it in GitHub Desktop.
Save nobrinskii/3917476 to your computer and use it in GitHub Desktop.
[vba/excel]出力するファイルで重複のないフルパスを取得する
'-------------------------------------------------------------------------------
'これから出力するファイルのフルパスを取得する
'-------------------------------------------------------------------------------
'【引数】出力先フォルダのパス(末尾に"\"あり),ファイル名(拡張子は含まない)
'【戻り値】出力するファイルのフルパス
'【備考】出力先に同名のファイルがある場合は"(x)"形式の文字列をファイル名の末尾に
' 付ける。
Private Function GetOutputFileFullPath(strFolderPath As String, _
strFileName As String, strExtension As String) As String
Dim FS As Object
Dim i As Integer
Dim strFullPath As String
Set FS = CreateObject("Scripting.FileSystemObject")
Do
strFullPath = strFolderPath & strFileName
If i > 0 Then
strFullPath = strFullPath & "(" & CInt(i) & ")"
End If
strFullPath = strFullPath & strExtension
If Not FS.FileExists(strFullPath) Then
Exit Do
End If
i = i + 1
Loop
Set FS = Nothing
GetOutputFileFullPath = strFullPath
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment