Changing Directory for GetOpenFileName

C

Chaplain Doug

Excel 2003. I am using

FName = Application.GetOpenFilename("Text Files (*.txt), *.txt", , "Select
ACH

to select a file to process. I want this dialog to open into a specific
folder. Right now it opens into my "My Documents" folder. I have tried:

Application.DefaultFilePath = "\\hqserver\shared\Finance\Payroll ACH Files"
and
Application.DefaultFilePath = "H:\Finance\Payroll ACH Files"

but neither seems to change the folder the GetOpenFilename looks in. How
may I accomplish what I am trying to accomplish? Thanks and God bless.
 
R

Ron de Bruin

Hi Chaplain

You must use ChDirNet, copy this at the top of your module

Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long

Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting path."
End Sub


Then use this in your macro

ChDirNet "\\ComputerName\YourFolder"
 
B

Bob Phillips

Try ChDir and ChDrive

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
C

Chaplain Doug

Dear Ron:

Works like a charm. Thanks. Why did not my approach work?
--
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org


Ron de Bruin said:
Hi Chaplain

You must use ChDirNet, copy this at the top of your module

Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long

Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting path."
End Sub


Then use this in your macro

ChDirNet "\\ComputerName\YourFolder"
 
R

Ron de Bruin

Hi Chaplain

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

This is not working if you want to use a network folder
ChDirNet is working for local and network folders

But your second example must work if you have used ChDrive and ChDir


--
Regards Ron de Bruin
http://www.rondebruin.nl


Chaplain Doug said:
Dear Ron:

Works like a charm. Thanks. Why did not my approach work?
 

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