![]() |
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 |
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 |
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 |
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 |
All times are GMT +1. The time now is 11:58 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com