Slightly different problem than I saw in other threads: When I step through this code it put the image in the worksheet but gives me an error on the line in bold:
The error is object variable or with block variable not set. If It didn't get hung up on the error it would be fine. The goal is an image not linked so if i sent it to someone it works.
Sub xxx()
Dim fName As String
Dim pic1 As Object
Dim r As Range
filelocation = Range("path").Value & "\"
sheetstotal = Sheets.Count 'ADD
path = filelocation
file = Dir(path)
i = sheetstotal - 1 'EDIT
If Dir(filelocation) = "" Then Exit Sub
filelocation = path + file
Set r = ActiveCell
Set pic1 = Nothing
pic1 = ActiveSheet.Shapes.AddPicture(Filename:=filelocation, LinkToFile:=False, SaveWithDocument:=True, Left:=r.Left, Top:=r.Top, Width:=r.Width * 8, Height:=r.Height * 22)
pic1.Select
End Sub
The error is object variable or with block variable not set. If It didn't get hung up on the error it would be fine. The goal is an image not linked so if i sent it to someone it works.
Sub xxx()
Dim fName As String
Dim pic1 As Object
Dim r As Range
filelocation = Range("path").Value & "\"
sheetstotal = Sheets.Count 'ADD
path = filelocation
file = Dir(path)
i = sheetstotal - 1 'EDIT
If Dir(filelocation) = "" Then Exit Sub
filelocation = path + file
Set r = ActiveCell
Set pic1 = Nothing
pic1 = ActiveSheet.Shapes.AddPicture(Filename:=filelocation, LinkToFile:=False, SaveWithDocument:=True, Left:=r.Left, Top:=r.Top, Width:=r.Width * 8, Height:=r.Height * 22)
pic1.Select
End Sub