PDA

View Full Version : [SOLVED:] Inserting Picture



elsone31
09-22-2016, 08:34 AM
Hello,

I keep getting that The specified file is not found with my code. The file path is correct any suggestions? Using excel 2013.

Thanks in advance.


Sub AddPicture()
Application.ScreenUpdating = False
Dim Student As Variant
Dim T As String
myDir = "Q:\ASSESSMENT\MIDDLE SCHOOLS\HERNANDEZ\ACADEMIC DATA ANALYSIS\ACADEMIC FACILITATORS"
'T = ".jpg"
Student = Range("G1")
ActiveSheet.Shapes.AddPicture Filename:=myDir & Student & ".jpg", linktofile:=msoFalse, _
savewithdocument:=msoTrue, Left:=300, Top:=10, Width:=120, Height:=120
Application.ScreenUpdating = True
End Sub

Paul_Hossler
09-22-2016, 09:33 AM
This works

I thought that maybe the spaces in the folders was causing an issue, but now I suspect that you are missing a backslash after the ACADEMIC FACILITATORS, but since G1 is not included ...




Option Explicit
Sub AddPicture()
Dim myDir As String
Dim Student As String
Dim T As String
Application.ScreenUpdating = False

' myDir = "Q:\ASSESSMENT\MIDDLE SCHOOLS\HERNANDEZ\ACADEMIC DATA ANALYSIS\ACADEMIC FACILITATORS"
' Student = Range("G1")
' T = ".jpg"


myDir = "C:\Users\Daddy\MYspace Documents\MYspace Pictures\" ' ------------- trailing backslash
Student = "Dilbert"
T = ".jpg"

MsgBox myDir & Student & T ' ------------------ helpful to debug

ActiveSheet.Shapes.AddPicture Filename:=myDir & Student & T, linktofile:=msoFalse, savewithdocument:=msoTrue, Left:=300, Top:=10, Width:=120, Height:=120

Application.ScreenUpdating = True

End Sub

elsone31
09-22-2016, 11:04 AM
THANK YOU Paul!!!! a backslash wow.

Thanks also for the pointer for using message box to help debug.