Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default How to set GetOpenFilename to a specific Folder

Sub Button104_Click()
Application.DefaultFilePath = "\\Server\server\Reports"
Application.GetOpenFilename ("PDF Reports (*.pdf), *.pdf")
End Sub


I am using the code above to try to always open the folder Reports on a server.

However if i select another folder, next time the code is run the previously selected folder is
opened.

How can i code this to ALWAYS open the specified folder ONLY ?


Corey....


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default How to set GetOpenFilename to a specific Folder

If you want to limit the user to that folder, you will need the to use the
API version with the OFN_NOCHANGEDIR flag:
http://vbnet.mvps.org/code/comdlg/fileopendlg.htm

Otherwise you could just use a list box and Dir( ) to it with the files
yourself.

If you mean that you always want to start with that folder, but the user can
navigate elsewhere, then set the CurDir before you call that function.

NickHK

"Corey" wrote in message
...
Sub Button104_Click()
Application.DefaultFilePath = "\\Server\server\Reports"
Application.GetOpenFilename ("PDF Reports (*.pdf), *.pdf")
End Sub


I am using the code above to try to always open the folder Reports on a

server.

However if i select another folder, next time the code is run the

previously selected folder is
opened.

How can i code this to ALWAYS open the specified folder ONLY ?


Corey....




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default How to set GetOpenFilename to a specific Folder

Nick,

How do i do that :

"set the CurDir before you call that function."
I do not know what CurDir is:
Is that Current Directory?

I though the Application.DefaultFilePath = "\\Server\server\Reports" does that ?


Corey...


"NickHK" wrote in message ...
If you want to limit the user to that folder, you will need the to use the
API version with the OFN_NOCHANGEDIR flag:
http://vbnet.mvps.org/code/comdlg/fileopendlg.htm

Otherwise you could just use a list box and Dir( ) to it with the files
yourself.

If you mean that you always want to start with that folder, but the user can
navigate elsewhere, then set the CurDir before you call that function.

NickHK

"Corey" wrote in message
...
Sub Button104_Click()
Application.DefaultFilePath = "\\Server\server\Reports"
Application.GetOpenFilename ("PDF Reports (*.pdf), *.pdf")
End Sub


I am using the code above to try to always open the folder Reports on a

server.

However if i select another folder, next time the code is run the

previously selected folder is
opened.

How can i code this to ALWAYS open the specified folder ONLY ?


Corey....





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default How to set GetOpenFilename to a specific Folder

That is only initially. You will probably navigate away from that during the
course of your Excel session.
Check out CurDir and CurDrive in the help

NickHK

"Corey" wrote in message
...
Nick,

How do i do that :

"set the CurDir before you call that function."
I do not know what CurDir is:
Is that Current Directory?

I though the Application.DefaultFilePath = "\\Server\server\Reports" does

that ?


Corey...


"NickHK" wrote in message

...
If you want to limit the user to that folder, you will need the to use the
API version with the OFN_NOCHANGEDIR flag:
http://vbnet.mvps.org/code/comdlg/fileopendlg.htm

Otherwise you could just use a list box and Dir( ) to it with the files
yourself.

If you mean that you always want to start with that folder, but the user

can
navigate elsewhere, then set the CurDir before you call that function.

NickHK

"Corey" wrote in message
...
Sub Button104_Click()
Application.DefaultFilePath = "\\Server\server\Reports"
Application.GetOpenFilename ("PDF Reports (*.pdf), *.pdf")
End Sub


I am using the code above to try to always open the folder Reports on a

server.

However if i select another folder, next time the code is run the

previously selected folder is
opened.

How can i code this to ALWAYS open the specified folder ONLY ?


Corey....







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to set GetOpenFilename to a specific Folder

Saved from a previous post:

If you refer to the folder\file by its UNC path
(\\something\somethingelse\filename.xls), you can use an API call. In fact,
this works with mapped drives, too:

Here's a sample, but with getsaveasfilename.

Option Explicit
Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long
Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting path."
End Sub


Sub testme01()

Dim myFileName As Variant
Dim myCurFolder As String
Dim myNewFolder As String
Dim Wkbk as workbook

myCurFolder = CurDir
myNewFolder = "\\share\folder1\folder2"

On Error Resume Next
ChDirNet myNewFolder
If Err.Number < 0 Then
'what should happen
MsgBox "Please change to your own folder"
Err.Clear
End If
On Error GoTo 0

myFileName = Application.GetOpenFilename(filefilter:="Excel Files, *.xls")

ChDirNet myCurFolder

If myFileName = False Then
Exit Sub 'user hit cancel
End If

'do your stuff to open it and process it.
Set wkbk = workbooks.open(filename:=myfilename)

'....

End Sub

Corey wrote:

Sub Button104_Click()
Application.DefaultFilePath = "\\Server\server\Reports"
Application.GetOpenFilename ("PDF Reports (*.pdf), *.pdf")
End Sub

I am using the code above to try to always open the folder Reports on a server.

However if i select another folder, next time the code is run the previously selected folder is
opened.

How can i code this to ALWAYS open the specified folder ONLY ?

Corey....


--

Dave Peterson


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
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? Raven Excel Discussion (Misc queries) 1 January 24th 06 03:28 PM
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? Raven[_2_] Excel Programming 1 January 24th 06 04:23 AM
GetOpenFilename Folder specfication Alan[_18_] Excel Programming 2 November 20th 03 12:15 AM
GetOpenFilename - Default Folder Andy Excel Programming 3 September 19th 03 04:20 PM
specifing default folder with GetOpenFilename Brian Excel Programming 3 September 8th 03 01:55 PM


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