Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Open files from specific directory

In VBA, I want to use the FindFile or GetOpenFileName
methods. I have a specific directory on a server (eg
\\server\groups\subdir\) that I want to show up in the
open dialog box. But both methods start out in the
directory I last opened from. The CHDIR command had no
effect. Any suggestions would be appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Open files from specific directory

Hi John,

You can do it with mapped drives, but I don't think it's possible without
API calls when you're using UNC paths. With a mapped drive:

ChDrive "U"
ChDir "U:\groups\subdir"

If you must use UNC paths, then this API-based code (posted originally by
Rob Bovey I think) should do the trick:

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

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

Sub ChDirUNC_OpenDialog()
On Error GoTo ErrHandler
SetUNCPath "\\LOGD0FILES\OGILVTW\Docs\Temp"
fname = Application.GetOpenFilename(FileFilter:="CSV Files
(*.csv),*.csv")
'Now open the file or what ever
Exit Sub
ErrHandler:
MsgBox "Couldn't set path"
End Sub


--
Regards,

Jake Marx
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


John Rawlins wrote:
In VBA, I want to use the FindFile or GetOpenFileName
methods. I have a specific directory on a server (eg
\\server\groups\subdir\) that I want to show up in the
open dialog box. But both methods start out in the
directory I last opened from. The CHDIR command had no
effect. Any suggestions would be appreciated.


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
open all files in directory davethewelder Excel Discussion (Misc queries) 2 August 26th 08 02:01 PM
How do you set Excel 2007 to open files in a specific folder? Opening to a specific folder Excel Discussion (Misc queries) 2 August 12th 07 02:58 AM
Open files in the same directory houghi Excel Discussion (Misc queries) 2 May 21st 07 03:56 PM
Macro - Open all word files in a directory Dileep Chandran Excel Worksheet Functions 11 December 19th 06 02:12 PM
Open all files in a directory Tom Waters[_2_] Excel Programming 1 September 3rd 03 12:59 PM


All times are GMT +1. The time now is 09:26 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"