Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Force save to CURRENT directory | Excel Programming | |||
Change current directory to the directory that the workbook loads from! | Excel Programming | |||
Force use of the Default Directory | Excel Programming | |||
How do I force an Excel macro to ask me which file and directory? | Excel Discussion (Misc queries) | |||
How to force current directory | Excel Programming |