Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
WCR WCR is offline
external usenet poster
 
Posts: 2
Default Specify Start Location for GetOpenFileName box

Can you specify the start location for the getopenfilename dialog box?

Dim f As String
f = Excel.Application.GetOpenFilename("LIS Files (*.lis), *.lis")

I would like to start the search in a specific location, instead of "My
Documents". Couldn't find any info on this topic yet.

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Specify Start Location for GetOpenFileName box

Hi WCR

Try this for C:\Data

Sub test()
Dim FName As Variant
Dim wb As Workbook
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = CurDir

MyPath = "C:\Data"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls")
If FName < False Then
Set wb = Workbooks.Open(FName)
MsgBox "your code"
wb.Close
End If

ChDrive SaveDriveDir
ChDir SaveDriveDir

End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"WCR" wrote in message ...
Can you specify the start location for the getopenfilename dialog box?

Dim f As String
f = Excel.Application.GetOpenFilename("LIS Files (*.lis), *.lis")

I would like to start the search in a specific location, instead of "My
Documents". Couldn't find any info on this topic yet.

Thanks!



  #3   Report Post  
Posted to microsoft.public.excel.programming
WCR WCR is offline
external usenet poster
 
Posts: 2
Default Specify Start Location for GetOpenFileName box

Thanks Ron - I was able to get it to work with a local folder, but it will
not work with a shared network folder. I can access the network folder by
typing in the path, but it won't work from within the macro. Any ideas?

old_path = CurDir
path = "\\network_computer\shared_drive"

ChDrive path
ChDir path

f = Excel.Application.GetOpenFilename("LIS Files (*.lis), *.lis")
Cells(2, 3) = f

ChDrive old_path
ChDir old_path

"Ron de Bruin" wrote:

Hi WCR

Try this for C:\Data

Sub test()
Dim FName As Variant
Dim wb As Workbook
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = CurDir

MyPath = "C:\Data"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls")
If FName < False Then
Set wb = Workbooks.Open(FName)
MsgBox "your code"
wb.Close
End If

ChDrive SaveDriveDir
ChDir SaveDriveDir

End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"WCR" wrote in message ...
Can you specify the start location for the getopenfilename dialog box?

Dim f As String
f = Excel.Application.GetOpenFilename("LIS Files (*.lis), *.lis")

I would like to start the search in a specific location, instead of "My
Documents". Couldn't find any info on this topic yet.

Thanks!




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Specify Start Location for GetOpenFileName box

Hi

Use this then

'Previously 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)
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting path."
End Sub

' sample usage

Sub FindFile()
Dim FName As Variant

ChDirNet "\\JELLE\YourFolder"
FName = Application.GetOpenFilename
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"WCR" wrote in message ...
Thanks Ron - I was able to get it to work with a local folder, but it will
not work with a shared network folder. I can access the network folder by
typing in the path, but it won't work from within the macro. Any ideas?

old_path = CurDir
path = "\\network_computer\shared_drive"

ChDrive path
ChDir path

f = Excel.Application.GetOpenFilename("LIS Files (*.lis), *.lis")
Cells(2, 3) = f

ChDrive old_path
ChDir old_path

"Ron de Bruin" wrote:

Hi WCR

Try this for C:\Data

Sub test()
Dim FName As Variant
Dim wb As Workbook
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = CurDir

MyPath = "C:\Data"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls")
If FName < False Then
Set wb = Workbooks.Open(FName)
MsgBox "your code"
wb.Close
End If

ChDrive SaveDriveDir
ChDir SaveDriveDir

End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"WCR" wrote in message ...
Can you specify the start location for the getopenfilename dialog box?

Dim f As String
f = Excel.Application.GetOpenFilename("LIS Files (*.lis), *.lis")

I would like to start the search in a specific location, instead of "My
Documents". Couldn't find any info on this topic yet.

Thanks!






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Specify Start Location for GetOpenFileName box

This seems to works too

const TheFolderPath = "\\Anywhere"
Application.GetOpenFilename(filefilter:="Excel Files (*.xls)," &
TheFolderPath & "\*.xls")

"WCR" wrote:

Can you specify the start location for the getopenfilename dialog box?

Dim f As String
f = Excel.Application.GetOpenFilename("LIS Files (*.lis), *.lis")

I would like to start the search in a specific location, instead of "My
Documents". Couldn't find any info on this topic yet.

Thanks!

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
Macro - save to current location vs excel default location leezard Excel Discussion (Misc queries) 0 October 28th 08 03:04 PM
OT :Start your own online business today !start making dollars [email protected] Excel Discussion (Misc queries) 0 May 6th 06 09:29 PM
GetOpenFileName with F*.txt DRK Excel Programming 6 June 7th 05 12:45 PM
Set Location and Filename to replace GetOpenFilename David Excel Programming 3 June 1st 05 02:29 PM
GetOpenFilename Daniel[_4_] Excel Programming 3 July 27th 03 11:00 AM


All times are GMT +1. The time now is 10:59 PM.

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"