Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Force to Directory

Hi,

I'm trying to write some code to force the current directory to an
other one, where my data files reside.

I have following code

In a module i have :
Public Const sFMTLogFile = "D:\Files\FMTLogFiles\"
Public Const sFMTPrefix = "FmtLog_Snr"

In another module i gave:

Sub OpenOneFile()
Dim fn As Variant
Dim OldDir As String

OldDir = ThisWorkbook.path
ChDir sFMTLogFile
fn = Application.GetOpenFilename("Text-files,*.txt", _
1, "Select One File To Open", , False)
If TypeName(fn) = "Boolean" Then Exit Sub
Workbooks.Open fn
End Sub

I was hoping that the ChDir would change the dir to the one preset in
the constant sFMTLogFile so that with the GetOpenFilename, the form
point to the desired directory, witch ist'n the case.

What goes wrong?

any help welcome

ludo
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Force to Directory

See if this does it


Sub OpenOneFile()
Dim fn As Variant
Dim OldDir As String

OldDir = ThisWorkbook.Path
ChDrive sFMTLogFile
ChDir sFMTLogFile
fn = Application.GetOpenFilename("Text-files,*.txt", _
1, "Select One File To Open", , False)
If TypeName(fn) = "Boolean" Then Exit Sub
Workbooks.Open fn
End Sub

--
__________________________________
HTH

Bob

"Ludo" wrote in message
...
Hi,

I'm trying to write some code to force the current directory to an
other one, where my data files reside.

I have following code

In a module i have :
Public Const sFMTLogFile = "D:\Files\FMTLogFiles\"
Public Const sFMTPrefix = "FmtLog_Snr"

In another module i gave:

Sub OpenOneFile()
Dim fn As Variant
Dim OldDir As String

OldDir = ThisWorkbook.path
ChDir sFMTLogFile
fn = Application.GetOpenFilename("Text-files,*.txt", _
1, "Select One File To Open", , False)
If TypeName(fn) = "Boolean" Then Exit Sub
Workbooks.Open fn
End Sub

I was hoping that the ChDir would change the dir to the one preset in
the constant sFMTLogFile so that with the GetOpenFilename, the form
point to the desired directory, witch ist'n the case.

What goes wrong?

any help welcome

ludo



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Force to Directory

Ludo,

Use ChDrive instead of ChDir:

ChDrive sFMTLogFile

Since it appears you are, in fact, changing the drive and not just the folder.

HTH,
Bernie
MS Excel MVP


"Ludo" wrote in message
...
Hi,

I'm trying to write some code to force the current directory to an
other one, where my data files reside.

I have following code

In a module i have :
Public Const sFMTLogFile = "D:\Files\FMTLogFiles\"
Public Const sFMTPrefix = "FmtLog_Snr"

In another module i gave:

Sub OpenOneFile()
Dim fn As Variant
Dim OldDir As String

OldDir = ThisWorkbook.path
ChDir sFMTLogFile
fn = Application.GetOpenFilename("Text-files,*.txt", _
1, "Select One File To Open", , False)
If TypeName(fn) = "Boolean" Then Exit Sub
Workbooks.Open fn
End Sub

I was hoping that the ChDir would change the dir to the one preset in
the constant sFMTLogFile so that with the GetOpenFilename, the form
point to the desired directory, witch ist'n the case.

What goes wrong?

any help welcome

ludo



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Force to Directory

And I'd change the drive/folder back before the subroutine finished:

Sub OpenOneFile()
Dim fn As Variant
Dim OldDir As String

OldDir = ThisWorkbook.Path
'did you mean this?????
'OldDir = CurDir

ChDrive sFMTLogFile
ChDir sFMTLogFile

fn = Application.GetOpenFilename("Text-files,*.txt", _
1, "Select One File To Open", , False)

ChDrive OldDir
ChDir OldDir

If TypeName(fn) = "Boolean" Then
Exit Sub
End If

Workbooks.Open fn
End Sub

Ludo wrote:

Hi,

I'm trying to write some code to force the current directory to an
other one, where my data files reside.

I have following code

In a module i have :
Public Const sFMTLogFile = "D:\Files\FMTLogFiles\"
Public Const sFMTPrefix = "FmtLog_Snr"

In another module i gave:

Sub OpenOneFile()
Dim fn As Variant
Dim OldDir As String

OldDir = ThisWorkbook.path
ChDir sFMTLogFile
fn = Application.GetOpenFilename("Text-files,*.txt", _
1, "Select One File To Open", , False)
If TypeName(fn) = "Boolean" Then Exit Sub
Workbooks.Open fn
End Sub

I was hoping that the ChDir would change the dir to the one preset in
the constant sFMTLogFile so that with the GetOpenFilename, the form
point to the desired directory, witch ist'n the case.

What goes wrong?

any help welcome

ludo


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Force save to CURRENT directory CLR Excel Programming 5 October 26th 07 03:10 PM
Change current directory to the directory that the workbook loads from! alondon Excel Programming 5 April 17th 07 06:05 AM
Force use of the Default Directory CLR Excel Programming 3 February 6th 07 09:20 PM
How do I force an Excel macro to ask me which file and directory? Ramius Excel Discussion (Misc queries) 4 January 14th 05 03:26 PM
How to force current directory CLR Excel Programming 8 November 30th 04 01:11 AM


All times are GMT +1. The time now is 08:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"