default location for files open commands

  • Thread starter Thread starter Eric Dreshfield
  • Start date Start date
E

Eric Dreshfield

I have the following code in a a macro:

ChDir "N:\pay\payroll\positive pay"
myfile = Application.GetOpenFilename("Text Files,*.txt")
Workbooks.OpenText FileName:=myfile, StartRow:=1,_
DataType:=xlDelimited, TextQualifier:=xlDoubleQuote,_
ConsecutiveDelimiter:=True, Tab:=True,_
Semicolon:=False, Comma:=False, Space:=True,_
Other:=False, FieldInfo:=Array(Array(1, 1),_
Array(2, 1), Array(3, 1))

Everytime I execute the macro it does not start the open
file command from N:\pay\payroll\positive pay....it starts
from what ever folder I last had excel looking in. Did I
not code this correctly ?

Thanks !
 
Each drive has a default directory.

ChDir "N:\pay\payroll\positive pay"

changes the default directory for the N drive, but if another drive is the
default drive, you will open in the default directory for that drive. To
make N the default drive as well

ChDrive "N"
ChDir "N:\pay\payroll\positive pay"


or
ChDrive "N:\pay\payroll\positive pay" ' uses first character in the string
ChDir "N:\pay\payroll\positive pay"
 
Tom,

Thanks....I now need to have a conversation with the
person whose macro I cloned that faulty coding from and
have them change their own macro so that it will work
consistently.

I'm so glad I found this newsgroup...it has been a wealth
of knowledge !

Thanks !
 
Back
Top