''-----------------------------------------------------------------------------------------------
''Passing to the parameter check directory path and checking the folder path is exists as Boolean
''-----------------------------------------------------------------------------------------------
Function FolderExists(Path As String)
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim hasFolder As Boolean
If FSO.FolderExists(Path) Then
hasFolder = True
Else
hasFolder = False
End If
Set FSO = Nothing
FolderExists = hasFolder
End Function
''-----------------------------------------------------------------------------------------------
''Create a new folder
''-----------------------------------------------------------------------------------------------
Sub CreateFolder(Path As String)
'Before create a folder check folder not exists
If FolderExists(Path) = False Then
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CreateFolder Path
Set FSO = Nothing
End If
End Sub
''-----------------------------------------------------------------------------------------------
''Get directory name form the file
''-----------------------------------------------------------------------------------------------
Function GetDirectoryName(filePath As String) As String
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim dirName As String
dirName = FSO.GetParentFolderName(filePath)
Set FSO = Nothing
GetDirectoryName = dirName
End Function
''-----------------------------------------------------------------------------------------------
''Copy file
''-----------------------------------------------------------------------------------------------
Sub CopyFile(CopyPath As String, SavePath As String)
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
' ''CopyFile into direcotry
' FSO.CopyFile "C:\Temp1\Book1.xls", "C:\Temp2\"
''CopyFile with name
FSO.CopyFile CopyPath, SavePath
Set FSO = Nothing
End Sub
''-----------------------------------------------------------------------------------------------
''File dialog select file
''-----------------------------------------------------------------------------------------------
Function SelectFilePath() As String
Dim intChoice As Integer
Dim strPath As String
'only allow the user to select one file
Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
'make the file dialog visible to the user
intChoice = Application.FileDialog(msoFileDialogOpen).Show
'determine what choice the user made
If intChoice <> 0 Then
'get the file path selected by the user
strPath = Application.FileDialog(msoFileDialogOpen).SelectedItems(1)
SelectFilePath = strPath
End If
End Function