0

When I debug the code below, it works perfectly. When I stop debugging, the width and height are not set. Can anyone help me figure out why?

Dim vWidth As Integer Dim vHeight As Integer Dim OleObj As OleObject

            Set rg = Range("B57:AX57")
            vWidth = rg.Width
            ws.Range("B" & vLastRow & ":" & "B" & vLastRow + 50).Select
            For Each cell In Application.Selection
                vHeight = vHeight + cell.Height
            Next cell
            'ws.Range("D" & vLastRow).Select
            ws.OLEObjects.Add FileName:=NewFilePath, Link:=False, DisplayAsIcon:=False, _
                                Top:=ws.Range("B" & vLastRow).Top, _
                                Left:=ws.Range("B" & vLastRow).Left
            For Each obj In ws.OLEObjects
                vOName = obj.Name
            Next
            Set OleObj = ws.OLEObjects(vOName)
            OleObj.ShapeRange.LockAspectRatio = msoFalse
            OleObj.Width = vWidth
            OleObj.Height = vHeight
  • Ruminating on some of the differences between "debug step-through" and "run normally", it might be that you need a couple of `DoEvents` or `Application.Calculate` in there to make sure everything has "finished" - for example, after the `ws.OLEObjects.Add` – Chronocidal Jul 10 '21 at 12:34
  • Thank you. I will try those options and see what works for me. – Gavin Bennett Jul 15 '21 at 10:22

0 Answers0