Created
October 19, 2012 10:40
-
-
Save nobrinskii/3917476 to your computer and use it in GitHub Desktop.
[vba/excel]出力するファイルで重複のないフルパスを取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'------------------------------------------------------------------------------- | |
'これから出力するファイルのフルパスを取得する | |
'------------------------------------------------------------------------------- | |
'【引数】出力先フォルダのパス(末尾に"\"あり),ファイル名(拡張子は含まない) | |
'【戻り値】出力するファイルのフルパス | |
'【備考】出力先に同名のファイルがある場合は"(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