Vincent88
Active Member
- Joined
- Mar 5, 2021
- Messages
- 382
- Office Version
- 2019
- Platform
- Windows
- Mobile
Hi Guys,
I use this code to insert anobject to a target cell in excel. This always open the Document folder to select image file. Is it possible to modify the code to select file from a desired folder instead ?
I use this code to insert anobject to a target cell in excel. This always open the Document folder to select image file. Is it possible to modify the code to select file from a desired folder instead ?
VBA Code:
Sub SelectOLE3()
Dim objFileDialog As Office.FileDialog
Set objFileDialog = Application.FileDialog(MsoFileDialogType.msoFileDialogFilePicker)
objFileDialog.AllowMultiSelect = False
objFileDialog.ButtonName = "Select File"
objFileDialog.Title = "Select File"
objFileDialog.Show
If (objFileDialog.SelectedItems.Count > 0) Then
Set f = ActiveSheet.OLEObjects.Add _
(Filename:=objFileDialog.SelectedItems(1), _
Link:=False, _
DisplayAsIcon:=True, _
IconLabel:=objFileDialog.SelectedItems(1), _
Top:=ActiveCell.Top, _
Left:=ActiveCell.Left _
)
f.Select
With f
.ShapeRange.LockAspectRatio = msoFalse
.Width = ActiveCell.Width
.Height = ActiveCell.Height
End With
ActiveCell.Value = objFileDialog.SelectedItems(1)
ActiveCell.ShrinkToFit = True
End If
Set f = Nothing
Set objFileDialog = Nothing
End Sub