Set Default Directory

B

bw

I sent this earlier, but without a subject, and the news group appears to require a subject,
so I'm sending it again....
--------------------------------------
I have the following two statements (among others, of course):

TheFileName = Application.GetOpenFilename("Text Files (*.txt), *.txt")

Workbooks.OpenText Filename:=TheFileName, Origin:=xlWindows, _
StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=myArray

I would like the default directory to begin looking in to be C:\

I have tried the following with no success:

TheFileName = Application.GetOpenFilename("Text Files (*.txt), C:\.txt")

Thanks,
Bernie
 
R

Ron de Bruin

I posted this:

Try this

I will save your default folder first to set it back at the end

Sub test()
Dim SaveDriveDir As String
Dim TheFileName As Variant
SaveDriveDir = CurDir
ChDrive "C"
ChDir "C:\"
TheFileName = Application.GetOpenFilename("Text Files (*.txt), C:\.txt")

MsgBox "your code"

ChDrive SaveDriveDir
ChDir SaveDriveDir
End Sub
 
R

Rob Bovey

Hi Bernie

This should do the trick for you:

ChDrive "C"
ChDir "C:\"
TheFileName = Application.GetOpenFilename("Text Files (*.txt), *.txt")

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *
 
S

steve

bw,

Know what you mean. For some reason I'm not seeing all the posts either.
But using Find is a big help. You can even have it search by sender.

steve
 

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

Similar Threads


Top