Firstly I'd like to apologise as I am a complete N00b when it comes to Excel and VBA. What I have picked up so far has been done with much help of Google, however I am now stuck and in need of some expert help.
I've got some code setup to insert an image into a specific location within an excel worksheet, but it would seem to be only linking to the picture file, so when I email the excel document to someone else, the pictures fail to load.
I understand I need to tell excel not to link to, but to save the image, but I am unsure on how to do this. So far my code looks like:
From looking at google I need to add:
But I've no clue where in the above code it needs to sit. I keep trying but keep getting errors when I run the code.
Any help really appreciated.
I've got some code setup to insert an image into a specific location within an excel worksheet, but it would seem to be only linking to the picture file, so when I email the excel document to someone else, the pictures fail to load.
I understand I need to tell excel not to link to, but to save the image, but I am unsure on how to do this. So far my code looks like:
Code:
Sub Photo1()
Application.ScreenUpdating = False
ActiveSheet.UnProtect Password:="Password"
Dim profile As String
On Error GoTo 0
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Filters.Clear
.Filters.Add "Picture Files", "*.bmp;*.jpg;*.gif;*.png"
.ButtonName = "Select"
.AllowMultiSelect = False
.Title = "Choose Photo"
.InitialView = msoFileDialogViewDetails
.Show
End With
ActiveSheet.Range("A1").Select
With ActiveSheet.Pictures.Insert(fd.SelectedItems(1), LinkToFile:=False, SaveWithDocument:=True)
.Left = ActiveSheet.Range("photograph1").Left
.Top = ActiveSheet.Range("photograph1").Top
.Placement = 1
.PrintObject = True
profile = .Name
End With
ActiveSheet.Pictures(profile).Select
With Selection.ShapeRange
.LockAspectRatio = msoFalse
.Width = 158
.Height = 142
End With
ActiveSheet.Protect Password:="Password"
End Sub
From looking at google I need to add:
Code:
LinkToFile:= False, SaveWithDocument:= True
But I've no clue where in the above code it needs to sit. I keep trying but keep getting errors when I run the code.
Any help really appreciated.