View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Paul Robinson Paul Robinson is offline
external usenet poster
 
Posts: 208
Default Selecting a directory from a form in excel

Hi
some code. Take care with line wrapping:

WBFullName = Application.GetOpenFilename("Excel Files(*.xls), *.xls",
Title:="Where is the File?")
If WBFullName = "False" Then 'form cancelled, so exit sub
Exit Sub
End If
'Get the file name
WBFileName = GetFileName(WBFullName)
If IsWorkBookOpen(WBFileName) Then 'workbook already open on
user
machine
'MsgBox "You already have this file open. Close it and try
again", vbOKOnly, "Help with Upload and Download"
Set MyWorkBook = Workbooks(WBFileName)
Else 'Get the file
Set MyWorkBook = Workbooks.Open(filename:=WBFullName)
End If

where GetFileName is

'See Green p80
'Returns the full file name from the end of a path by looking for
first \
'If no \, returns the file name
Public Function GetFileName(FullPathString As String) As String
Dim stPathSep As String 'Path separator, \
Dim FPLength As Integer 'length of FullPathString
Dim i As Integer 'counter
stPathSep = Application.PathSeparator
FPLength = Len(FullPathString)
For i = FPLength To 1 Step -1
If Mid(FullPathString, i, 1) = stPathSep Then Exit For
Next i
GetFileName = Right(FullPathString, FPLength - i)
End Function


regards
Paul


(ennui) wrote in message . com...
Hello,

On a form I need to create in Excel I have to be able to 'Open'
several workbooks and summarise their information into one workbook.
In order to do this I need to be able to select which directory the
workbooks are in.

Is there an easy way to do this from a form in Excel? If I click an
'Open' button can I create a little pop up menu that allows me to
select the directory I wish to be in?

Any help would be greatly appreciated.
ennui