none
VBA - Build table using two Modules RRS feed

  • Question

  • Hi all,

    I have build a program in Excel VBA that builds a PowerPoint file with cell information and graphs. I am building a big table for one slide. Everything works fine, but the table is so big that the information is too much for one module.

    I begin with:

    Set Table = newPowerPoint.ActivePresentation.Slides(2).Shapes.AddTable(12, 17)
            With Table

    Within this 'With', I program everything concerning font size, colors, etc..

    This 'With' has to be used in the second module to make sure the table is fully build.

    How can I manage to build the first piece of the table in Module1 and the second piece of the same table in Module2. The result has to be one table.

    Thanks in advance

    Ganesh


    Wednesday, January 18, 2017 3:53 PM

Answers

  • Hi ganeshgebhard,

    refer the code below.

    Sub demo2()
    Dim oTbl As Table
    Set oTbl = ActiveWindow.Selection.ShapeRange(1).Table
    With oTbl.Cell(1, 1)
    .Shape.Fill.ForeColor.RGB = RGB(100, 150, 200)
    End With
    End Sub

    second time create the object of table and select the same table and apply formatting.

    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.

    • Marked as answer by ganeshgebhard Monday, January 23, 2017 9:10 AM
    Monday, January 23, 2017 6:38 AM
    Moderator

All replies

  • Hi ganeshgebhard,

    you had mentioned that,"the table is so big that the information is too much for one module."

    How much big?

    did you try to create an another object of the same table in module 2 ?

    so both the object will refer to the same table.

    when first module get executed it will apply some formatting and when second module get execute it will apply the rest of the formatting.

    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, January 19, 2017 1:41 AM
    Moderator
  • Hi Deepak,

    Big = 12 rows and 17 columns, building from scratch. 

    Let me put it this way: Module 1 creates the table in PowerPoint and fills it in partially. Module 2 has to finish this filling.

    So I think your idea of using an object sounds perfect, but how do I do that?

    Ganesh


    Thursday, January 19, 2017 7:00 AM
  • Hi ganeshgebhard,

    in your original post you already created an object and add the table.

    so with that you can add some formatting in first module.

    in second you need to select the same table and create it's object to add more formatting.

    table is already created so second time we just need to select that same table.

    create it's object and with that object format it.

    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, January 20, 2017 7:59 AM
    Moderator
  • Hi Deepak,

    And how can I manage this? Do you have some code?

    Ganesh


    Friday, January 20, 2017 10:14 AM
  • Hi ganeshgebhard,

    refer the code below.

    Sub demo2()
    Dim oTbl As Table
    Set oTbl = ActiveWindow.Selection.ShapeRange(1).Table
    With oTbl.Cell(1, 1)
    .Shape.Fill.ForeColor.RGB = RGB(100, 150, 200)
    End With
    End Sub

    second time create the object of table and select the same table and apply formatting.

    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.

    • Marked as answer by ganeshgebhard Monday, January 23, 2017 9:10 AM
    Monday, January 23, 2017 6:38 AM
    Moderator