Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Opening all files located in a specific directory | Excel Programming | |||
opening directory from excel | Excel Programming | |||
opening directory from excel | Excel Programming | |||
opening directory from excel | Excel Programming | |||
opening a workbook in the current directory | Excel Programming |