Glaswegian
Well-known Member
- Joined
- Oct 14, 2003
- Messages
- 1,487
Hi
I picked up some code from the board for saving and zipping a file - but it's actually for saving a folder. I only understand some of the code and would like to save a file rather than a folder. I changed some of the code to ask for a file(folder) location several times and then stop but it still wants to zip the file.
How do I amend the code to look for a file rather than a folder and also make the routine stop if no file is selected?
Regards
I picked up some code from the board for saving and zipping a file - but it's actually for saving a folder. I only understand some of the code and would like to save a file rather than a folder. I changed some of the code to ask for a file(folder) location several times and then stop but it still wants to zip the file.
How do I amend the code to look for a file rather than a folder and also make the routine stop if no file is selected?
Code:
Function GetFolderName(Msg As String) As String
' returns the name of the folder selected by the user
Dim bInfo As BROWSEINFO, path As String, r As Long
Dim X As Long, pos As Integer
bInfo.pidlRoot = 0& ' Root folder = Desktop
If IsMissing(Msg) Then
bInfo.lpszTitle = "Select a file."
' the dialog title
Else
bInfo.lpszTitle = Msg ' the dialog title
End If
bInfo.ulFlags = &H1 ' Type of directory to return
X = SHBrowseForFolder(bInfo) ' display the dialog
' Parse the result
path = Space$(512)
r = SHGetPathFromIDList(ByVal X, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
GetFolderName = Left(path, pos - 1)
Else
GetFolderName = ""
End If
End Function
Sub TestGetFolderName()
Dim oFSObj As Object
tryagain: 'forces folder selection..can't exit
cnt = cnt + 1
foldername = GetFolderName("Select a folder")
If foldername = "" Then
MsgBox "You didn't select a folder."
If cnt < 3 Then 'change number of attempts
GoTo tryagain
Else
Set fsoObj = Nothing
cnt = 0
MsgBox "A file was not selected."
End If
End If
End Sub
Regards