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

  • Thread starter Thread starter jason
  • Start date Start date
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
 
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)\
 
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
 
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
 
Thanks to everybody for help
(Like the little touch of restoring initial settings at the end of your routine Ron)

thanks again
jason
 

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

Back
Top