MUST BE POSSIBLE !! ..........

J

jason

....I want to use the GetOpenFile method to set a variable that is an
excel file i.e:

MyAllocPathway = Application.GetOpenFilename("Excel Files (*.xls),
*.xls, Add- in Files (*.xla), *.xla", 1, "Select Excel you wish to
attach")

this works ok

Is it possible so that whenever this is actioned it opens with the
contents of a specific folder?

I've tried putting this infront of the above line, but itdoesn't seem
to work:

ChDir ("I:\Fin\Val data\OLA\OLAB figures (Weekly)\")

Any help greatly appreciated,
Jason
 
D

DNF Karran

You are changing the deafult directory on the I drive but are no
switching to that drive- You also don't need the brackets unless yo
are assiging it to a variable.

Duncan

chdrive "I"
chdir "I:\Fin\Val data\OLA\OLAB figures (Weekly)\
 
C

Chip Pearson

Jason,

It should work if you use ChDir prior to calling GetOpenFilename.
You may need to use ChDrive to change the drive. E.g,

ChDrive "I:"
ChDir "I:\Fin\Val data\OLA\OLAB figures (Weekly)\"
MyAllocPathway = Application.GetOpenFilename("Excel Files
(*.xls),
*.xls, Add- in Files (*.xla), *.xla", 1, "Select Excel you wish
to
attach")


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
R

Ron de Bruin

Hi Jason

Here is a example that is also using ChDrive

Sub test()
Dim SaveDriveDir As String, MyPath As String
Dim FName As Variant

SaveDriveDir = CurDir
MyPath = "C:\Data"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files, *.xls")

If FName = False Then
'do nothing
Else
'your code
End If

ChDrive SaveDriveDir
ChDir SaveDriveDir
End Sub
 
J

jason

Thanks to everybody for help
(Like the little touch of restoring initial settings at the end of your routine Ron)

thanks again
jason
 
Top