How to set 'insert picture' default open location

J

Jack B. Pollack

Hi,

using application.dialogs( xldialoginsertpicture) to open a dialog box. How
can I control the path that the dialog box open with?
 
M

Mike H

Hmmm,

I thought that would be as easy as changing to the correct directory before
calling the dialog but it seems to want to default to My Pictures. Here's an
alternative

Const MyPath As String = "Your Full path"
ChDir MyPath
MyPicture = Application.GetOpenFilename _
(filefilter:=("JPG files,*.jpg"), Title:="Select picture", MultiSelect:=False)
If MyPicture = False Then Exit Sub
ActiveSheet.Pictures.Insert (MyPicture)

Mike
 
P

Peter T

It looks like the default picture folder is found from an API and seems that
can't be changed. Following does similar albeit more work.

Sub test()
Dim oldDir As String
Dim lookFldr As String
Dim vFile

lookFldr = "C:\" ' << change

oldDir = CurDir
ChDir lookFldr
'Err.Clear
' add more picture extensions as required
vFile = Application.GetOpenFilename("Picture
Files,*.jpg;*.bmp;*.tif;*.gif", , _
"Insert your wonderful picture in cell " & ActiveCell.Address(0,
0))
If VarType(vFile) = vbString Then
ActiveSheet.Pictures.Insert vFile
ElseIf VarType(vFile) = vbError Then
MsgBox "GetOpenFilename failed"
Else
'if vfile = false user cancelled
End If

ChDir oldDir
End Sub

Regards,
Peter T
 
J

Jack B. Pollack

Thank you. This was helpful


Mike H said:
Hmmm,

I thought that would be as easy as changing to the correct directory before
calling the dialog but it seems to want to default to My Pictures. Here's an
alternative

Const MyPath As String = "Your Full path"
ChDir MyPath
MyPicture = Application.GetOpenFilename _
(filefilter:=("JPG files,*.jpg"), Title:="Select picture", MultiSelect:=False)
If MyPicture = False Then Exit Sub
ActiveSheet.Pictures.Insert (MyPicture)

Mike
 
J

Jack B. Pollack

Thank you. This was helpful


Peter T said:
It looks like the default picture folder is found from an API and seems that
can't be changed. Following does similar albeit more work.

Sub test()
Dim oldDir As String
Dim lookFldr As String
Dim vFile

lookFldr = "C:\" ' << change

oldDir = CurDir
ChDir lookFldr
'Err.Clear
' add more picture extensions as required
vFile = Application.GetOpenFilename("Picture
Files,*.jpg;*.bmp;*.tif;*.gif", , _
"Insert your wonderful picture in cell " & ActiveCell.Address(0,
0))
If VarType(vFile) = vbString Then
ActiveSheet.Pictures.Insert vFile
ElseIf VarType(vFile) = vbError Then
MsgBox "GetOpenFilename failed"
Else
'if vfile = false user cancelled
End If

ChDir oldDir
End Sub

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top