Heres 1 method - It moves the file
Place all the code in a normal module
Run MoveFile
Private Type BrowseInfo ' used by the function GetFolderName
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BrowseInfo) As Long
Sub TestGetFolderName()
Dim FolderName As String
FolderName = GetFolderName("Select a folder")
If FolderName = "" Then
MsgBox "You didn't select a folder."
Else
MsgBox "You selected this folder: " & FolderName
End If
End Sub
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 folder."
' 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 MoveFile()
Dim sFile As String
Dim sFname As String
Dim sToFolder As String
Dim iPos As Integer
sFile = Application.GetOpenFilename
If sFile = "False" Then
Exit Sub
End If
iPos = InStrRev(sFile, "\")
sFname = Right(sFile, Len(sFile) - (iPos))
sToFolder = GetFolderName("Select Folder")
If sToFolder = "" Then
Exit Sub
End If
Name sFile As sPath & sToFolder & "\" & sFname
End Sub
Bookmarks