Open a workbook from within a specified folder

G

Guest

Good morning, all,

My workbook contains a cell called "Foldername" which currently contains the
following value:

I have a macro,

Sub WorkbookOpen()
On Error Resume Next
ChDir (Sheets("Database").Range("FolderName").Value)
WorkbookToOpen = Application.GetOpenFilename()
Workbooks.Open Filename:=WorkbookToOpen
End Sub

When the FileOpen dialog is displayed, I want the default directory to be
whatever is contained in Foldername. ChDir Doesn't seem to work. Van anyone
advise me how to get around this?

Regards & thanks in advance

Pete
 
R

Ron de Bruin

Hi Peter

This is working for me

Sub test()
Dim FName As Variant
Dim wb As Workbook
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = CurDir

MyPath = Sheets("Database").Range("FolderName").Value

ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls")
If FName <> False Then
Set wb = Workbooks.Open(FName)
MsgBox "your code"
wb.Close
End If

ChDrive SaveDriveDir
ChDir SaveDriveDir

End Sub
 
G

Guest

Ron,

"ChDrive Mypath" drops out - could this be because "FolderName" begins with
\\ and not a drive letter? I have to do it this way, as the system is used by
multiple users, not all of whom map to the drive using the same letter.

Cheers

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top