Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ll ll is offline
external usenet poster
 
Posts: 67
Default Defining Current Directory

Hi,
I'm working with a form that has an 'open' box and a 'save as' box.
How can I specify that the 'current directory' is equal to the
directory in which the spreadsheet with the form resides?
Here is what I have so far: Thanks - Louis
----------------------
Public Sub listfilesinfoldersandsub1()


Dim i As Long
Dim Path As String
Dim Prompt As String
Dim Title As String
Dim TempArr() As String
Dim PathName As String
Dim NewFN As String

With Application.FileSearch


Dim SaveDriveDir As String
SaveDriveDir = CurDir

ChDir (SaveDriveDir)
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files
(*.xls), *.xls", Title:="Please select a file")

If NewFN = False Then

MsgBox "Stopping because you did not select a file"
Exit Sub
Else


.FileType = msoFileTypeAllFiles
.SearchSubFolders = False
.Execute

PathName = NewFN


UserForm1.TextBox1.Value = PathName

End If


End With

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default Defining Current Directory

Is it not just a case of using ActiveWorkbook.Path ?

"ll" wrote:

Hi,
I'm working with a form that has an 'open' box and a 'save as' box.
How can I specify that the 'current directory' is equal to the
directory in which the spreadsheet with the form resides?
Here is what I have so far: Thanks - Louis
----------------------
Public Sub listfilesinfoldersandsub1()


Dim i As Long
Dim Path As String
Dim Prompt As String
Dim Title As String
Dim TempArr() As String
Dim PathName As String
Dim NewFN As String

With Application.FileSearch


Dim SaveDriveDir As String
SaveDriveDir = CurDir

ChDir (SaveDriveDir)
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files
(*.xls), *.xls", Title:="Please select a file")

If NewFN = False Then

MsgBox "Stopping because you did not select a file"
Exit Sub
Else


.FileType = msoFileTypeAllFiles
.SearchSubFolders = False
.Execute

PathName = NewFN


UserForm1.TextBox1.Value = PathName

End If


End With

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
ll ll is offline
external usenet poster
 
Posts: 67
Default Defining Current Directory

On May 25, 11:15 am, Ben McBen
wrote:
Is it not just a case of using ActiveWorkbook.Path ?

"ll" wrote:
Hi,
I'm working with a form that has an 'open' box and a 'save as' box.
How can I specify that the 'current directory' is equal to the
directory in which the spreadsheet with the form resides?
Here is what I have so far: Thanks - Louis
----------------------
Public Sub listfilesinfoldersandsub1()


Dim i As Long
Dim Path As String
Dim Prompt As String
Dim Title As String
Dim TempArr() As String
Dim PathName As String
Dim NewFN As String


With Application.FileSearch


Dim SaveDriveDir As String
SaveDriveDir = CurDir


ChDir (SaveDriveDir)
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files
(*.xls), *.xls", Title:="Please select a file")


If NewFN = False Then


MsgBox "Stopping because you did not select a file"
Exit Sub
Else


.FileType = msoFileTypeAllFiles
.SearchSubFolders = False
.Execute


PathName = NewFN


UserForm1.TextBox1.Value = PathName


End If


End With


End Sub


thanks
Well, that works ok with local files, but when I try to put the file
on the network and run it from there, "My Documents" becomes my
directory, for some reason. The msgbox displays the correct path, but
the file directory that opens is still "My Documents."
Here's what I've got now:
------------------
Dim i As Long
Dim Path As String
Dim Prompt As String
Dim Title As String
Dim TempArr() As String
Dim PathName As String
Dim NewFN As String

With Application.FileSearch


Dim SaveDriveDir As String
SaveDriveDir = CurDir

SaveDriveDir = ActiveWorkbook.Path

ChDir SaveDriveDir
MsgBox SaveDriveDir
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files
(*.xls), *.xls", Title:="Please select a file")


If NewFN = False Then

MsgBox "Stopping because you did not select a file"
Exit Sub
Else


.FileType = msoFileTypeAllFiles
.SearchSubFolders = False
.Execute

PathName = NewFN


UserForm1.TextBox1.Value = PathName

End If
ChDrive SaveDriveDir
ChDir SaveDriveDir

End With

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Defining Current Directory

Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long

Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
Debug.Print lReturn
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting path."
End Sub

sample usage:

Sub FindFile()
ChDirNet "\\LOGD0FILES\OGILVTW\Docs\Temp"
Application.Dialogs(xlDialogFindFile).Show
End Sub

--
Regards,
Tom Ogilvy


"ll" wrote:

On May 25, 11:15 am, Ben McBen
wrote:
Is it not just a case of using ActiveWorkbook.Path ?

"ll" wrote:
Hi,
I'm working with a form that has an 'open' box and a 'save as' box.
How can I specify that the 'current directory' is equal to the
directory in which the spreadsheet with the form resides?
Here is what I have so far: Thanks - Louis
----------------------
Public Sub listfilesinfoldersandsub1()


Dim i As Long
Dim Path As String
Dim Prompt As String
Dim Title As String
Dim TempArr() As String
Dim PathName As String
Dim NewFN As String


With Application.FileSearch


Dim SaveDriveDir As String
SaveDriveDir = CurDir


ChDir (SaveDriveDir)
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files
(*.xls), *.xls", Title:="Please select a file")


If NewFN = False Then


MsgBox "Stopping because you did not select a file"
Exit Sub
Else


.FileType = msoFileTypeAllFiles
.SearchSubFolders = False
.Execute


PathName = NewFN


UserForm1.TextBox1.Value = PathName


End If


End With


End Sub


thanks
Well, that works ok with local files, but when I try to put the file
on the network and run it from there, "My Documents" becomes my
directory, for some reason. The msgbox displays the correct path, but
the file directory that opens is still "My Documents."
Here's what I've got now:
------------------
Dim i As Long
Dim Path As String
Dim Prompt As String
Dim Title As String
Dim TempArr() As String
Dim PathName As String
Dim NewFN As String

With Application.FileSearch


Dim SaveDriveDir As String
SaveDriveDir = CurDir

SaveDriveDir = ActiveWorkbook.Path

ChDir SaveDriveDir
MsgBox SaveDriveDir
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files
(*.xls), *.xls", Title:="Please select a file")


If NewFN = False Then

MsgBox "Stopping because you did not select a file"
Exit Sub
Else


.FileType = msoFileTypeAllFiles
.SearchSubFolders = False
.Execute

PathName = NewFN


UserForm1.TextBox1.Value = PathName

End If
ChDrive SaveDriveDir
ChDir SaveDriveDir

End With

End Sub


  #5   Report Post  
Posted to microsoft.public.excel.programming
ll ll is offline
external usenet poster
 
Posts: 67
Default Defining Current Directory

On May 25, 2:20 pm, Tom Ogilvy
wrote:
Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long

Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
Debug.Print lReturn
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting path."
End Sub

sample usage:

Sub FindFile()
ChDirNet "\\LOGD0FILES\OGILVTW\Docs\Temp"
Application.Dialogs(xlDialogFindFile).Show
End Sub

--
Regards,
Tom Ogilvy

"ll" wrote:
On May 25, 11:15 am, Ben McBen
wrote:
Is it not just a case of using ActiveWorkbook.Path ?


"ll" wrote:
Hi,
I'm working with a form that has an 'open' box and a 'save as' box.
How can I specify that the 'current directory' is equal to the
directory in which the spreadsheet with the form resides?
Here is what I have so far: Thanks - Louis
----------------------
Public Sub listfilesinfoldersandsub1()


Dim i As Long
Dim Path As String
Dim Prompt As String
Dim Title As String
Dim TempArr() As String
Dim PathName As String
Dim NewFN As String


With Application.FileSearch


Dim SaveDriveDir As String
SaveDriveDir = CurDir


ChDir (SaveDriveDir)
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files
(*.xls), *.xls", Title:="Please select a file")


If NewFN = False Then


MsgBox "Stopping because you did not select a file"
Exit Sub
Else


.FileType = msoFileTypeAllFiles
.SearchSubFolders = False
.Execute


PathName = NewFN


UserForm1.TextBox1.Value = PathName


End If


End With


End Sub


thanks
Well, that works ok with local files, but when I try to put the file
on the network and run it from there, "My Documents" becomes my
directory, for some reason. The msgbox displays the correct path, but
the file directory that opens is still "My Documents."
Here's what I've got now:
------------------
Dim i As Long
Dim Path As String
Dim Prompt As String
Dim Title As String
Dim TempArr() As String
Dim PathName As String
Dim NewFN As String


With Application.FileSearch


Dim SaveDriveDir As String
SaveDriveDir = CurDir


SaveDriveDir = ActiveWorkbook.Path


ChDir SaveDriveDir
MsgBox SaveDriveDir
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files
(*.xls), *.xls", Title:="Please select a file")


If NewFN = False Then


MsgBox "Stopping because you did not select a file"
Exit Sub
Else


.FileType = msoFileTypeAllFiles
.SearchSubFolders = False
.Execute


PathName = NewFN


UserForm1.TextBox1.Value = PathName


End If
ChDrive SaveDriveDir
ChDir SaveDriveDir


End With


End Sub


Thanks Tom
That did the trick.

Regards,
Louis



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
Change current directory to the directory that the workbook loads from! alondon Excel Programming 5 April 17th 07 06:05 AM
current directory Ross[_2_] Excel Discussion (Misc queries) 1 April 2nd 07 10:00 PM
Current Directory Mallasch Excel Discussion (Misc queries) 4 September 15th 06 03:05 AM
get current directory Souris Excel Programming 1 September 27th 05 11:53 AM
changing current directory to that of the current open file unnameable Excel Programming 2 May 19th 04 11:14 AM


All times are GMT +1. The time now is 07:55 AM.

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"