Hello, I need help with this. I found a thread from previous posts, and it has a code that's doing what I want, and it's working perfect. Taking multiple pictures and inserting them one below.
There's only one problem I need solution. Code has a default-folder selected for pictures, "C:\etc.", I need modify this code so that it opens me a browser where to select right folder, because my default-folder can be anything else.
Here's the code I found
Here's the code I was previously using. I need to connect these two codes into one. I've tried everything but this goes beyond my abilities :P Can you help me with this?
There's only one problem I need solution. Code has a default-folder selected for pictures, "C:\etc.", I need modify this code so that it opens me a browser where to select right folder, because my default-folder can be anything else.
Here's the code I found
Code:
Sub 123()
InsertAllPix Range("A50"), _
"C:\Documents and Settings\123\My Pictures\My Directory", _
"*.jpg"
End Sub
Sub InsertAllPix(r As Range, ByVal sDir As String, sFilt As String)
Dim **** As String
Dim iRow As Long
If Right(sDir, 1) <> "\" Then sDir = sDir & "\"
**** = Dir(sDir & sFilt)
Do While Len(****)
iRow = iRow + 1
With ActiveSheet.Pictures.Insert(sDir & ****)
.ShapeRange.LockAspectRatio = msoFalse
.Height = r(iRow, 1).Height
.Width = r(iRow, 1).Width
.Top = r(iRow, 1).Top
.Left = r(iRow, 1).Left
.Placement = xlMoveAndSize
End With
**** = Dir
Loop
End Sub
Here's the code I was previously using. I need to connect these two codes into one. I've tried everything but this goes beyond my abilities :P Can you help me with this?
Code:
Sub ExampleUsage()
Dim myPicture As String, myRange As Range
myPicture = Application.GetOpenFilename _
("Pictures (*.gif; *.jpg; *.bmp; *.tif),*.gif; *.jpg; *.bmp; *.tif", _
, "Select Picture to Import")
If myPicture = "False" Then
Exit Sub
End If
Set myRange = Range("A50")
InsertAndSizePic myRange, myPicture
End Sub
Sub InsertAndSizePic(Target As Range, PicPath As String)
Dim p As Picture
Application.ScreenUpdating = False
Set p = ActiveSheet.Pictures.Insert(PicPath)
If Target.Cells.Count = 1 Then Set Target = Target.MergeArea
With Target
p.Top = .Top
p.Left = .Left
p.Width = .Width
p.Height = .Height
p.Placement = xlMoveAndSize
End With
End Sub
Last edited: