Hi everyone ;
I'm a .NET software developer facing an issue with Excel Macro, can anyone help me please :
Issue :
- > Error message : an error occurred while importing this File.
- > Scenario : I have an xlsm file that is connected to a web API through multiple queries, the query get's also images name from database so that after some columns print the images passing by the like + image name (https://........./images/.....jpg) there is a macro and VBA behind it I'll print it down below.
the file used to work fine until on day some microsoft and office 365 update came, the file now throws the "an error occurred while importing this File" which i think happens when the excel file tries to load images.
Any one can help to bypass that issue, i'm not good in macros/Excel so I can't think I can settle the issue alone.
Down below the VB / Macro code for the images (don't know really what it does) :
>>> You opened this thread as Ask an Excel Question ... instead of VBA Macros <<<
>>> Moved to correct Forum <<<
>>> use code - tags <<<
I'm a .NET software developer facing an issue with Excel Macro, can anyone help me please :
Issue :
- > Error message : an error occurred while importing this File.
- > Scenario : I have an xlsm file that is connected to a web API through multiple queries, the query get's also images name from database so that after some columns print the images passing by the like + image name (https://........./images/.....jpg) there is a macro and VBA behind it I'll print it down below.
the file used to work fine until on day some microsoft and office 365 update came, the file now throws the "an error occurred while importing this File" which i think happens when the excel file tries to load images.
Any one can help to bypass that issue, i'm not good in macros/Excel so I can't think I can settle the issue alone.
Down below the VB / Macro code for the images (don't know really what it does) :
>>> You opened this thread as Ask an Excel Question ... instead of VBA Macros <<<
>>> Moved to correct Forum <<<
>>> use code - tags <<<
Code:
Sub SuppressionImage(CasePourPhoto As Range)
Dim Sh As Shape
With CasePourPhoto.Worksheet
For Each Sh In .Shapes
If Not Application.Intersect(Sh.TopLeftCell, CasePourPhoto.MergeArea) Is Nothing Then
Sh.Delete
End If
Next Sh
End With
End Sub
Sub SelectionImage(CasePourPhoto As Range)
Dim Sh As Shape
CasePourPhoto.Select
With CasePourPhoto.Worksheet
For Each Sh In .Shapes
If Not Application.Intersect(Sh.TopLeftCell, CasePourPhoto.MergeArea) Is Nothing Then
Sh.Select
End If
Next Sh
End With
End Sub
Function URLPictureInsert(URL As String, CasePourPhoto As Range) As String
Dim Pshp As Shape
Dim xRg As Range
Dim xCol As Long
Dim FirstWorksheet As Worksheet
On Error Resume Next
FirstWorksheet = Application.ActiveSheet
'Application.ScreenUpdating = False
Set Rng = CasePourPhoto
For Each cell In Rng
CasePourPhoto.Worksheet.Activate
SuppressionImage CasePourPhoto
If Not FirstWorksheet Is Nothing Then
If CasePourPhoto.Worksheet.CodeName <> FirstWorksheet.CodeName Then Exit Function
End If
On Error Resume Next
CasePourPhoto.Worksheet.Activate
CasePourPhoto.Worksheet.Pictures.Insert(URL).Select
SelectionImage CasePourPhoto
Set Pshp = Selection.ShapeRange.Item(1)
'If Pshp = Nothing Then Exit For
xCol = cell.Column
Set xRg = CasePourPhoto.Worksheet.Cells(cell.Row, xCol)
With Pshp
.LockAspectRatio = msoFalse
.Width = xRg.MergeArea.Width - xRg.MergeArea.Width / 10
.Height = xRg.MergeArea.Height - xRg.MergeArea.Height / 10
.Top = xRg.Top + (xRg.MergeArea.Height - .Height) / 2
.Left = xRg.Left + (xRg.MergeArea.Width - .Width) / 2
'Pshp.Select
'Set octl = Application.CommandBars.FindControl(ID:=6382)
'Application.SendKeys "%(oe){TAB}{UP}"
'Application.CommandBars.ExecuteMso "PicturesCompress"
'octl.Execute
End With
lab:
Set Pshp = Nothing
'Range("A2").Select
Next
'Application.ScreenUpdating = True
URLPictureInsert = "Image Updated at " & Now
End Function
Last edited by a moderator: