Search code examples
excelvb.net

Excel macro execution error in VN.Net code


In a vb.net application, I call an Excel object in which I run a macro. Everything works, but when my application takes over, it crashes with this error message.

System.InvalidOperationException HResult=0x80131509 Message=Impossible de résoudre toutes les références de propriété dans le chemin de la propriété 'LayoutTransform.ScaleX'. Vérifiez que les objets applicables prennent en charge les propriétés. Source=PresentationFramework

translated:

System.InvalidOperationException HResult=0x80131509 Message=Unable to resolve all property references in the path of the 'LayoutTransform.ScaleX' property. Verify that the applicable objects support the properties. Source=PresentationFramework

Public Sub RunMacroNomOrdo()
    Dim oExcel As New Excel.Application
    Dim oBook As Excel.Workbook
    oBook = oExcel.Workbooks.Open(_nFicNomOrdo)
    oExcel.Visible = True
    Try
        oExcel.Run("NomOrdo", _nFicNomCatia, _nFicAttribs)
    Catch ex As Exception
    End Try
End Sub

Solution

  • I open and run the macro in a BackgroundWorker. This solves the problem.