I don't know VBA, but I was able to make this simple VBA code from watching multiple Youtube videos.
Basically, it allows you to put a complete filename of a photo in cell "A2", press the "Refresh" button, and the picture will be displayed. Then the file can be saved with that picture displayed. When the worksheet is re-opened, that picture will still be displayed as it was, but if the "Refresh" button is pressed and the actual picture was changed in the directory filename, the picture on the page will refresh.
Here is the code...
I want to add three things to this, but need help....
First...The ability to display (assign) a "short" name to the full filename of the photo.....
If I have several photos of islands in my island directory, I may want it to display the name "Hawaaii", but reference the full filename.
Maybe for this, have a control button. Activate a cell, click on the button and pop-up displays with "actual filename?" and "display name?" inputs.
Second... Have the top-left corner of the picture display in the cell under the "Display Name" cell.
Third... Have the ability to have several "Display Name" cells and reference pictures.
Thanks so much in advance!
Basically, it allows you to put a complete filename of a photo in cell "A2", press the "Refresh" button, and the picture will be displayed. Then the file can be saved with that picture displayed. When the worksheet is re-opened, that picture will still be displayed as it was, but if the "Refresh" button is pressed and the actual picture was changed in the directory filename, the picture on the page will refresh.
Here is the code...
Code:
Private Sub cmdDisplayPhoto_Click()
Application.ScreenUpdating = False
Dim myObj
Dim Pictur
Set myObj = ActiveSheet.DrawingObjects
For Each Pictur In myObj
If Left(Pictur.Name, 7) = "Picture" Then
Pictur.Select
Pictur.Delete
End If
Next
Dim PictureName As String
PictureName = Range("A2")
On Error GoTo errormessage:
ActiveSheet.Shapes.AddPicture Filename:=PictureName, linktofile:=msoFalse, savewithdocument:=msoTrue, Left:=190, Top:=30, Width:=300, Height:=300
errormessage:
If Err.Number = 1004 Then
MsgBox "File does not exist." & vbCrLf & "Check the filename again"
Range("A2").Value = ""
End If
Application.ScreenUpdating = True
End Sub
I want to add three things to this, but need help....
First...The ability to display (assign) a "short" name to the full filename of the photo.....
If I have several photos of islands in my island directory, I may want it to display the name "Hawaaii", but reference the full filename.
Maybe for this, have a control button. Activate a cell, click on the button and pop-up displays with "actual filename?" and "display name?" inputs.
Second... Have the top-left corner of the picture display in the cell under the "Display Name" cell.
Third... Have the ability to have several "Display Name" cells and reference pictures.
Thanks so much in advance!