Hi All
An import image code I have used for years has stopped working, It has the error
! File not found: The file that you're trying to insert is no longer available
This hasn't been a problem before, and has been working happily for about 8 years! It doesn't seem to be able to be cancelled out through normal VBA?
Here is my code
>>> use code - tags <<<
Appreciate any input as it is driving me crazy!!!
Digby
An import image code I have used for years has stopped working, It has the error
! File not found: The file that you're trying to insert is no longer available
This hasn't been a problem before, and has been working happily for about 8 years! It doesn't seem to be able to be cancelled out through normal VBA?
Here is my code
>>> use code - tags <<<
Code:
Sub Insert_Image()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Sheets("Summary").Select
Dim inputCell As String
Dim outputCell As String
Dim filePath As String
Dim imageHeight As Integer
Dim imageWidth As Integer
Dim stopRow As Integer
Dim X As Range
' Specify the location values
inputCell = "D" ' The column which has the image names
outputCell = "G" ' The column you want the picture to go into
imageHeight = 50 ' The width of the image you are inserting
imageWidth = 60 ' The width of the image you are inserting
stopRow = 1500 ' How many rows to look for so that the loop stops.
' Specify when to stop the loop (this is needed as there are spaces between the cells ' so you need to tell excel when to finish and not look forever.
For Each X In Range(inputCell + "1", Range(inputCell & stopRow).End(xlUp))
' If the value of the cell is empty move on to the next one.
If X <> "" Then
With X.Offset(1, 0)
' Set the image output to be the outputcell specified above on the same row.
Range(outputCell & X.Row).Select
' Check to see if the image exists, if not move on and ignore
On Error Resume Next
If Dir(filePath + X) <> "" Then
' If the iamge exists insert the picture.
ActiveSheet.Pictures.Insert(filePath + X).Select
' Once the image is inserted, using the aspect ratio change the width to a specified value
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Width = imageWidth
Selection.ShapeRange.Height = imageHeight
On Error GoTo 0
End If
On Error Resume Next
End With
End If
NextX:
Next X
ActiveSheet.DrawingObjects.Select
Selection.PrintObject = msoFalse
Selection.PrintObject = msoTrue
Selection.Placement = xlMoveAndSize
Application.CommandBars("Format Object").Visible = False
Application.ScreenUpdating = False
Range("B3").Select
' ActiveSheet.Pictures.Select
Dim s As String
Dim pic As Picture
Dim Rng As Range
Set ws = ActiveWorkbook.Worksheets("Summary")
Set Rng = ws.Range("A5:Z5000")
'Sheets("summary").Select
'Dim shp As Shape
'For Each shp In ActiveSheet.Shapes
'If Not shp.Type = msoFormControl Then shp.Delete
'Next
For Each pic In ActiveSheet.Pictures
With pic
s = .TopLeftCell.Address & ":" & .BottomRightCell.Address
End With
If Not Intersect(Rng, ws.Range(s)) Is Nothing Then
pic.ShapeRange.IncrementTop 0.75
pic.ShapeRange.IncrementLeft 0.75
End If
' Next
Dim CellTopLeft As Range
'For Each pic In ws.Pictures
With pic
Set CellTopLeft = .TopLeftCell
If CellTopLeft.Column <> 7 Then Set CellTopLeft = CellTopLeft.EntireRow.Cells(1, 7) '*****This statement added
If Not Intersect(Rng, CellTopLeft) Is Nothing Then
.Top = (CellTopLeft.Top + CellTopLeft.Height / 2) - .Height / 2
.Left = (CellTopLeft.Left + CellTopLeft.Width / 2) - .Width / 2
End If
End With
Next
On Error GoTo 0
Range("B2").Select
Range("F5").Select
Range("B2").Select
Application.ScreenUpdating = True
Application.DisplayAlerts =True
End Sub
Appreciate any input as it is driving me crazy!!!
Digby
Last edited by a moderator: