Problems with photo insertion macro

glturner13

New Member
Joined
Jun 5, 2018
Messages
2
Hey guys! Long time lurker, just can’t seem to find the solution to my problem. I have a workbook with a sheet that gets pictures inserted into it with text boxes and other notations on top of the photos. Up until now we did all of this manually (insert, resize, send to back, etc). I managed to piece together a macro from other similar posts that does exactly what i want: I click a button, the open photo dialog opens, i select a picture, it asks which cell i want to place it in, i click the cell then hit OK and everyrhing inserts properly sized and at the back.

My problem here is that the images ate being hyperlinked instead of actually inserted into the document. This is a network share file and i don’t have the ability to permanently store the photos on the drive so i need them to be physically inserted and saved into the workbook. This works fine when you manually insert an image, just not with my macro.

I’ve been racking my brain on this and can'tseem to figure out what i need to fix/ change. Any ideas???

Here’s my code for the sub:

Sub piccy()
Dim sFile As Variant, r As Range
sFile = Application.GetOpenFilename(FileFilter:="Pic Files (*.jpg;*.bmp;*.png), *.jpg;*.bmp;*.png", Title:="Browse to select a picture")
If sFile = False Then Exit Sub
On Error Resume Next
Set r = Application.InputBox("Click in the cell to hold the picture", Type:=8)
On Error GoTo 0
If r Is Nothing Then Exit Sub
If r.Count > 1 Then Exit Sub
ActiveSheet.Pictures.Insert (sFile)
With ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
.LockAspectRatio = False
.Top = r.Top
.Left = r.Left
.Height = r.MergeArea.Height
.Width = r.MergeArea.Width
.ZOrder msoSendToBack
End With
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
I was able to get this solved for my needs by piecing together a new macro. Here is the updated macro if anyone runs into this problem as well:

Sub TestInsertPictureInRange()
Application.ScreenUpdating = False
Dim picToOpen As String, r As Range
On Error Resume Next
picToOpen = Application.GetOpenFilename(FileFilter:="Pic Files (*.jpg;*.bmp;*.png), *.jpg;*.bmp;*.png", Title:="Browse to select a picture")
Set r = Application.InputBox("Click in the cell to hold the picture", Type:=8)
On Error GoTo 0
If r Is Nothing Then Exit Sub
If r.Count > 1 Then Exit Sub
If picToOpen <> "" Then
ActiveSheet.Shapes.AddPicture Filename:=picToOpen, linktofile:=msoFalse, _
savewithdocument:=msoCTrue, Left:=r.Left, Top:=r.Top, Width:=r.MergeArea.Width, Height:=r.MergeArea.Height
End If
With ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
.LockAspectRatio = False
.ZOrder msoSendToBack
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top