none
vb.net app Using Fill.TwoColorGradient works when formatting shape in PowerPoint 2013 but fails with 2016 RRS feed

  • Question

  • I am automating PowerPoint from a vb.net app that draws shapes on PowerPoint slide. This works very well with PowerPoint 2013. When the same code is run on another machine that is using PowerPoint 2016 it fails to apply the gradient. It produces error -2147221163 (Interface not registered).

    Am I missing an obvious difference between the two versions of PowerPoint?

    Sunday, February 26, 2017 3:16 PM

All replies

  • Hi AndesUK,

    from the description of the thread I find that your code is working in powerpoint 2013 but it giving you an error on powerpoint 2016.

    I am not sure what is the cause for this issue as you did not posted your code.

    if you post your code then we can try to test it on our side.

    you had mentioned that issue is related with Fill.TwoColorGradient. so I try to make a test with that on my side with code below with Powerpoint 2016.

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim ppApplication As PowerPoint.Application = Nothing
            Dim ppPresentation As PowerPoint.Presentation = Nothing
            Dim ppSlide As PowerPoint.Slide = Nothing
            Dim ppTextRange As PowerPoint.TextRange = Nothing
            Dim ppShape As PowerPoint.Shape = Nothing
            Dim tFrm As PowerPoint.TextFrame = Nothing
    
    
    
            Dim fileTest As String = "C:\Users\v-padee\Desktop\MyPresentation.pptx"
            ppApplication = New Microsoft.Office.Interop.PowerPoint.Application()
            ppApplication.Visible = Microsoft.Office.Core.MsoTriState.msoTrue
            ppPresentation = ppApplication.Presentations.Add
                ppApplication.WindowState = PowerPoint.PpWindowState.ppWindowMinimized
    
    
    
            ppSlide = ppPresentation.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
                With ppSlide.Shapes.Item(1).TextFrame.TextRange
                .Text = "Sample Presentation"
                .Font.Name = "Arial Black"
                    .Font.Size = 22
                    .Font.Color.RGB = RGB(255, 0, 0)
                End With
    
    
            ppShape = ppSlide.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 50, 100, 100, 100)
    
            ppShape.Fill.TwoColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientDiagonalDown, 1)
    
            ppSlide = Nothing
    
    
        End Sub

    Output:

    you can see that it is working correctly on my side.

    you can try to test this code on your side.

    Reference:

    FillFormat.TwoColorGradient Method

    Regards

    Deepak

    Monday, February 27, 2017 1:52 AM
    Moderator
  • Hi Deepak,

    Thanks for your reply. I have copied your code, modified as required to run it under vb.net (see below) and the result is still as I reported, i.e. an exception occurs on the line that attempts to apply the gradient, but only when running with PowerPoint 2016. It run perfectly under PowerPoint 2013.

    This is the modified code:

    Imports Microsoft.Office.Interop
    Imports Microsoft.Office.Interop.PowerPoint
    Public Class Form1
        Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
            Dim ppApplication As Microsoft.Office.Interop.PowerPoint.Application = Nothing
            Dim ppPresentation As Microsoft.Office.Interop.PowerPoint.Presentation = Nothing
            Dim ppSlide As Microsoft.Office.Interop.PowerPoint.Slide = Nothing
            Dim ppTextRange As Microsoft.Office.Interop.PowerPoint.TextRange = Nothing
            Dim ppShape As Microsoft.Office.Interop.PowerPoint.Shape = Nothing
            Dim tFrm As Microsoft.Office.Interop.PowerPoint.TextFrame = Nothing
            Dim fileTest As String = "C:\Users\luis\Desktop\MyPresentation.pptx"
            ppApplication = New Microsoft.Office.Interop.PowerPoint.Application()
            ppApplication.Visible = Microsoft.Office.Core.MsoTriState.msoTrue
            ppPresentation = ppApplication.Presentations.Add
            ppApplication.WindowState = PowerPoint.PpWindowState.ppWindowMinimized
            ppSlide = ppPresentation.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
            With ppSlide.Shapes.Item(1).TextFrame.TextRange
                .Text = "Sample Presentation"
                .Font.Name = "Arial Black"
                .Font.Size = 22
                .Font.Color.RGB = RGB(255, 0, 0)
            End With
            ppShape = ppSlide.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 50, 100, 100, 100)
            ppShape.Fill.TwoColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientVertical, 1)
            With ppShape.Fill
                .GradientAngle = 0
                .GradientStops(1).Color.RGB = RGB(0, 0, 255)
                .GradientStops(1).Position = 0.25
                .GradientStops(2).Color.RGB = RGB(0, 255, 0)
                .GradientStops(2).Position = 0.25
            End With
            ppSlide = Nothing
        End Sub

    End Class

    And this is the result:

    System.Runtime.InteropServices.COMException (0x80040155): Interface not registered (Exception from HRESULT: 0x80040155)

    What I have tried:

    I have repaired the Office Professional 2016 installation, but that had no effect. I have also tried using the OneColorGradient method, which also fails when the vb.net is automating PowerPoint 2016, but works with 2013.

    • Edited by AndesUK Monday, February 27, 2017 8:44 AM
    Monday, February 27, 2017 8:14 AM
  • Hi AndesUK,

    from your description of the last post , I assume that this is related with that specific machine.

    I think if you try to test this code on different machine then it can work without any error.

    I find that this error occur because of some thing is not registered correctly in registry.

    you already tried to repair the MS Office but did not solve the issue.

    do you have MS Office 2013 and 2016 both versions install on that machine?

    if yes then try to uninstall then and try to reinstall the MS Office 2016 and then try to test the code.

    there is no issue with the code that I can confirm.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 28, 2017 5:51 AM
    Moderator
  • Hi Deepak,

    I should have pointed out that I run two machines, both on the same version and build of Windows 10. One has Office 2013 (my development machine) and the other Office 2016 (test system). The repair I mentioned was done on the machine with Office 2016. I will, nevertheless, remove and re-install Office completely on that machine and test again. Will report back.

    Tuesday, February 28, 2017 4:41 PM
  • Hi AndesUK,

    generally , when you try to develop some code then it is good if both development and testing machines have same version of office installed.

    the different versions may cause some issue or misunderstanding at the time of testing. but it happens in rare cases.

    also it is a good approach to use the latest version for development.

    because latest version can support older versions but older version may not support newer version if something get changed in newer version.

    but in your case , I don't think that there is any version issue.

    because same code working on my 2016 version.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 1, 2017 5:29 AM
    Moderator
  • Hi Deepak,

    I think you may be reaching the wrong conclusion. My evidence demonstrates a different behaviour of the same code when working with two difference versions of PowerPoint (2013 and 2016). The only requirement we can impose on customers running this app is that they must be running Windows 10 (build 14393 or later). The difference in behaviour for the .net app can only be attributed to PowerPoint, as all other elements (Operating system, app version) are the same. Your code is for VBA, not for .net, which is why I clearly stated that I had to modify it for it to run under .net. What all this seems to point to is a difference in the VBA code and the PowerPoint interop implemented under the .net framework.

    Monday, March 13, 2017 12:16 PM
  • Hi AndesUK,

    below is your modified code that you had pasted above in your previous post and you are getting an error in powerpoint 2016.

    I try to run that code on my machine.

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim ppApplication As Microsoft.Office.Interop.PowerPoint.Application = Nothing
            Dim ppPresentation As Microsoft.Office.Interop.PowerPoint.Presentation = Nothing
            Dim ppSlide As Microsoft.Office.Interop.PowerPoint.Slide = Nothing
            Dim ppTextRange As Microsoft.Office.Interop.PowerPoint.TextRange = Nothing
            Dim ppShape As Microsoft.Office.Interop.PowerPoint.Shape = Nothing
            Dim tFrm As Microsoft.Office.Interop.PowerPoint.TextFrame = Nothing
    
            Dim fileTest As String = "C:\Users\v-padee\Desktop\demopresentation.pptx"
            ppApplication = New Microsoft.Office.Interop.PowerPoint.Application()
            ppApplication.Visible = Microsoft.Office.Core.MsoTriState.msoTrue
            ppPresentation = ppApplication.Presentations.Add
            ppApplication.WindowState = PowerPoint.PpWindowState.ppWindowMinimized
    
            ppSlide = ppPresentation.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
            With ppSlide.Shapes.Item(1).TextFrame.TextRange
                .Text = "Sample Presentation"
                .Font.Name = "Arial Black"
                .Font.Size = 22
                .Font.Color.RGB = RGB(255, 0, 0)
            End With
    
            ppShape = ppSlide.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 50, 100, 100, 100)
            ppShape.Fill.TwoColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientVertical, 1)
            With ppShape.Fill
                .GradientAngle = 0
                .GradientStops(1).Color.RGB = RGB(0, 0, 255)
                .GradientStops(1).Position = 0.25
                .GradientStops(2).Color.RGB = RGB(0, 255, 0)
                .GradientStops(2).Position = 0.25
    
            End With
            ppSlide = Nothing
        End Sub

    I get output below.

    I did not get any error.

    if I comment the modified code then I get output below.

    I am using windows10 and powerpoint 2016 and its your modified code for vb.net.

    so we can say that code does not have any problem.

    so further I try to find the details regarding this error.

    but I find that this error can occur with any application due to different reasons.

    so there is no any specific documentation available for this error for powerpoint application.

    you had mentioned that,"What all this seems to point to is a difference in the VBA code and the PowerPoint interop implemented under the .net framework."

    let me inform you that VBA and VB.Net uses the same object model. so there is no any difference for the properties and methods.

    the difference is only in the syntax.

    as I already show you that your code is working on my side for powerpoint 2016.

    I suggest you to install the fresh copy of MS Office 2016 then install the latest updates and try again.

    if that not solve the issue then you may try to reinstall the Visual studio.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 14, 2017 9:11 AM
    Moderator
  • Deepak, your result is very interesting indeed (and possibly good news if it turns out to be the machine with PowerPoint 2016 that is at fault). I have removed and re-installed it, without any change in behaviour. I will check for updates once again and if that does not solve the problem I will re-install Visual Studio 2015.

    Obviously if Visual Studio 2015 is the problem, then I have a bigger problem with potentially many users experiencing the difficulty I reported.

    When the app fails in my case, in addition to the error messages I note that the effect on the object with the gradient is exactly as you report, i.e. the transition from one colour to the other is not sharp, because the positioning of the stops is what did not get executed. The stops are found at the two ends of the rectangle.

    • Edited by AndesUK Wednesday, March 15, 2017 2:12 PM
    Wednesday, March 15, 2017 2:01 PM
  • Hi AndesUK,

    you can try to implement the suggestion I gave you last time.

    also I suggest you to run the same code on different machine that have same configuration like windows10, powerpoint 2016 and visual studio 2015.

    so currently I think this issue is related to specific machine and on other machine it will run fine.

    so after that you can try to find the difference between that two machines and try to correct it.

    so that it can start to work on your machine too.

    Regards

    Deepak 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 16, 2017 8:15 AM
    Moderator
  • Today I removed Office 2016 and re-loaded and run the unchanged code under Visual Studio 2017 on that machine (Operating system as on my development machine, Windows 10.0.14393). It failed in the same ways I reported. Hence, I can only conclude that PowerPoint has a subtle change between the two version, which affects the way the .net app behaves.

    Any thoughts?

    Thursday, March 16, 2017 2:58 PM
  • Hi AndesUK,

    which version of powerpoint you have currently.

    below version is installed on my machine.

    below is visual studio version.

    below is windows version.

    try to install the latest update for MS Office and try again.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 17, 2017 8:25 AM
    Moderator