PDA

View Full Version : [SOLVED:] I want the path of the Workbook



v_gyku
09-08-2005, 10:48 PM
I have a code which is allowing user to select a workbook in open dialog.
All the sheets in the selected workbook are displayed in a listbox.
How will i get the folder name(COmplete path of the workbook except the workbook name)


Set SheetList = New Collection
FName = Application.GetOpenFileName("Excel Files (*.xls),*.xls")
If FName <> "False" Then
Set Wkb = Workbooks.Open(FileName:=FName)
End If
txtFileLocation = FName
For Each ws In Wkb.Worksheets
SheetList.Add ws.name
Next
Wkb.Close SaveChanges:=False
n = SheetList.Count
For i = 1 To n
UserControl.List1.AddItem SheetList(i)
Next i
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Set SheetList = Nothing
Set ws = Nothing
Set Wkb = Nothing

Jacob Hilderbrand
09-08-2005, 10:51 PM
FolderPath = Replace(FName, Wkb.Name, "")

Justinlabenne
09-09-2005, 12:11 AM
In the kb, these functions may help:

http://vbaexpress.com/kb/getarticle.php?kb_id=757

http://vbaexpress.com/kb/getarticle.php?kb_id=767

sheeeng
09-09-2005, 04:33 AM
FolderPath = Replace(FName, Wkb.Name, "")

Great! Jake.