How do I set a default path when using Application.GetOpenFilename

  • Thread starter Thread starter pkohler
  • Start date Start date
P

pkohler

I am using a macro to help a user put an image into an excel sheet.
would like for the user to be able to click on the button an
automatically be browsing the directory that the excel sheet is in, bu
if not that then I would like to declair a default variable.
Currently, when you click button it defaults to "My Documents". Th
Code Snipit in question is bellow. Any suggestions?

Dim filename As String

filename = Application.GetOpenFilename("Picture
(*.jpg;*.gif;*.bmp), *.jpgs;*.gif;*.bmp", , "Grab Your Logo",
"False")

If filename = "False" Then
Application.ScreenUpdating = True
Call protect
Exit Sub
Else


Thank
 
Hi
add the following at the beginning
ChDir "C:\your_desired_default_location"

or
ChDir Activeworkbook.path
 
I prefer the following as it takes care of different drives and networks

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

Sub SetUNCPath(sPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(sPath)
If lReturn = 0 Then _
MsgBox "Error setting path."
End Sub

Bob Flanagan
Macro Systems
Delaware, U.S. 302-234-9857
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel
 
Back
Top