Setting the Width and Height of an embedded OLEObject in an excel worksheet

206 views Asked by At

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
0

There are 0 answers