Help with converting an Excel Macro to Office Script.

David Allison 0 Reputation points
2023-10-23T13:57:31.65+00:00

Can anyone help me in converting the below Excel Macro to Office Script?

Sub URLPictureInsert()
    Dim theShape As Shape
    Dim xRg As Range
    Dim xCol As Long
    On Error Resume Next
    Application.ScreenUpdating = False
    Set Rng = ActiveSheet.Range("B5")
    For Each cell In Rng
        Filename = cell
        If InStr(UCase(Filename), "JPG") > 0 Then
            ActiveSheet.Pictures.Insert(Filename).Select
            Set theShape = Selection.ShapeRange.Item(1)
            If theShape Is Nothing Then GoTo isnill
            xCol = cell.Column + 1
            Set xRg = Cells(cell.Row, xCol)
            With theShape
                .LockAspectRatio = msoFalse
                .Width = 315
                .Height = 200
                .Top = xRg.Top + (xRg.Height - .Height) / 750
                .Left = xRg.Left + (xRg.Width - .Width) / 11
            End With
isnill:
            Set theShape = Nothing
            Range("A2").Select
        End If
    Next
    Application.ScreenUpdating = True

    Debug.Print "Done " & Now

Range("B5").ClearContents

End Sub
Microsoft 365 and Office Development Other
Microsoft 365 and Office Install, redeem, activate For business Windows
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.