Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Opening a directory using code

Using the following I can open a window showing the files in that directory;

Application.Dialogs(xlDialogOpen).Show "\\Rfp_main\rfp2005\templates"

However if someone tries to load a file ... say Word.. in that directory,
excel tries to import it into the open workbook. How can I rempve the focus
back to the workbook and close it, thus leaving only the open window on the
desktop with excel now closed down ?

Thanks
--
Robert Pollock
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Opening a directory using code

You showing the Excel file=Open dialog, just as if it were select from the
menus - so you can't divorce its built in functionality.

Try using Application.GetOpenFileName (that displays the same dialog) which
just returns a string with the fully qualified path and name of the file
selected. Then you can have your code take the appropriate action. You
would need to change the default directory to control which directory it
opened to.

For local drives you can use Chdrive and Chdir. for a network directory
(code originally posted by Rob Bovey):

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

Example Usage:

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

--
Regards,
Tom Ogilvy



"Robert Pollock" wrote in message
...
Using the following I can open a window showing the files in that

directory;

Application.Dialogs(xlDialogOpen).Show "\\Rfp_main\rfp2005\templates"

However if someone tries to load a file ... say Word.. in that directory,
excel tries to import it into the open workbook. How can I rempve the

focus
back to the workbook and close it, thus leaving only the open window on

the
desktop with excel now closed down ?

Thanks
--
Robert Pollock



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
Opening all files located in a specific directory DaSo Excel Programming 2 January 25th 05 08:05 AM
opening directory from excel Pradyumna. Excel Programming 1 June 16th 04 01:27 PM
opening directory from excel Pradyumna Excel Programming 1 June 16th 04 12:01 PM
opening directory from excel Pradyumna Excel Programming 0 June 16th 04 11:57 AM
opening a workbook in the current directory Richard[_16_] Excel Programming 2 August 30th 03 02:46 AM


All times are GMT +1. The time now is 01:35 PM.

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

About Us

"It's about Microsoft Excel"