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
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