Following my vba practices, I am writing a code to open in a worksheet a picture below the last row with data.
The code reads Range("A2").value and open the image with the same value in StudentPhotos carpet
My code sends the cursor below the last row with data where I need to open the image.
Range("A1").End(xlDown).Offset(2, 0).Select
My code opens the image but, as I said, I need VBA displays the image from the empty cell.
This is my code:
Sub displayphotobelowlastrow_Click()
Application.ScreenUpdating = False
Dim myDir As String
Dim student_id As Double, P As String
myDir = "C:\Users\Me\Desktop\Students\StudentPhotos\"
student_id = Range("A2")
P = ".jpg"
ActiveSheet.Shapes.AddPicture Filename:=myDir & student_id & P, linktofile:=msoFalse, savewithdocument:=msoTrue, Left:=10, Top:=100, Width:=120, Height:=120
Application.ScreenUpdating = True
End Sub
On the other hand, in myDir I am trying to use the relative path :
myDir = CurrentProject.Path & "\ StudentPhotos\ StudentPhotos\"
but, VBA displays "Invalid Qualifier Error"
Could I ask another pair of eyes to take a look and offer some advice?
Thank you for taking the time in helping me.
Bookmarks