Slide (unknown member) : Integer out of range. 0 is not in the valid range of 1 to 12 RRS feed

  • Question

  • Sorry my English :)

    I try to set the background color for second slide from fifth slide

    static void Main(string[] args)
        var presentationPath = @"d:\myPresentation.pptx";
        var app = new PowerPoint.Application();
        var presentation = app.Presentations.Open(presentationPath, WithWindow: MsoTriState.msoFalse);
        var slide2 = presentation.Slides[2];
        var slide5 = presentation.Slides[5];
        slide2.FollowMasterBackground = MsoTriState.msoFalse;
        var backgroundStyle = slide5.BackgroundStyle;
            slide2.BackgroundStyle = backgroundStyle;
        catch (Exception exception)
            Console.WriteLine($@"Slide5.BackgroundStyle: {backgroundStyle.ToString()}");

    but code throw exception (second line):

    Slide5.BackgroundStyle: msoBackgroundStyleNotAPreset

    Slide (unknown member) : Integer out of range. 0 is not in the valid range of 1 to 12.

    Wednesday, March 28, 2018 2:51 PM


  • Hi adamShakhabov,

    You had mentioned that,"You got error:  Integer out of range. 0 is not in the valid range of 1 to 12"

    It's because , You need to pass the value between 1 to 12.

    Currently you are passing the 0 cause this issue.

    The root cause is that Slide 5 does not contain any backgroundstyle.

    To solve the issue. Open your presentation.

    Select Slide number 5. In PowerPoint 2016 , Go to Design Tab -> open the drop down in group 'Variants' like below.

    Save the presentation and close it.

    Now run your code. You will notice that your code will run without any error.

    Below is the debugging result on my side. You can notice the value of "slide5.BackgroundStyle".


    Slide.BackgroundStyle Property (PowerPoint)

    MsoBackgroundStyleIndex Enumeration (Office)



    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

    Thursday, March 29, 2018 4:48 AM