使用Table.ApplyStyle与表样式进行交互

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

【e800编译】此示例中演示如何以编程方式在Microsoft PowerPoint 2010演示文稿中与表样式互动。

此代码段是Office 2010的101项VBA代码示例中的一部分。与其它示例一样,这些将可以直接写入您的代码中。

每块示例代码包含约5至50行的代码,分别演示了一个独特的功能或功能集,在VBA 或VB以及C#中(在Visual Studio 2010中创建)。每个示例之中都会包含代码以及相应注释,这样您就可以直接运行获取预期的结果,或者是根据代码注释提示来调整环境,运行示例代码。

Microsoft Office 2010提供了你所需要的工具来创建功能强大的应用程序。Microsoft Visual Basic Application(VBA)代码示例可以帮助你创建自己的应用程序,以执行特定功能或者以此为出发点实现更为复杂的功能。

实例代码

将此代码复制到演示文稿中中一个模块。并列放置VBA窗口与PowerPoint窗口,按F8(然后按住Shift+ F8)单步执行。

Sub TableStyleDemo()

' Create a new slide with a simple table:

Dim sld As Slide

Set sld=ActivePresentation.Slides.Add(2,ppLayoutTable)

sld.Select

Dim tbl As Table

Set tbl=sld.Shapes.AddTable(4,4).Table

FillTabletbl

' In order to apply a style to a table, you must know the

' StyleID associated with the style. This information is not documented

' nor is there any way to retrieve this information for all the styles.

' This sample includes a list of all the table styles for PowerPoint 2010

' at the end of the sample. These values are not guaranteed to work in

' any other version of PowerPoint.

With tbl.Cell(3,3).Shape.TextFrame.TextRange

.Font.Size=24

EndWith

' Apply Light Style 1 - Accent 3, preserving existing styles.

tbl.ApplyStyle"{C083E6E3-FA7D-4D7B-A595-EF9225AFEA82}",True

Debug.Print": "&

Debug.Print"Style.Id : "&tbl.Style.Id

' Apply Dark Style 2 - Accent 5/Accent 6, without preserving styles. ' Note that this changes the Bold font back to normal, but doesn't affect ' font size:

tbl.ApplyStyle"{46F890A9-2807-4EBB-B81D-B2AA78EC7F39}",False

Debug.Print": "&

Debug.Print"Style.Id : "&tbl.Style.Id

EndSub

Sub FillTable(tbl As Table)

' Fill a table with sample data.

Dim row As Integer

Dim col As Integer

For col=1To tbl.Columns.Count

tbl.Cell(1,col).Shape.TextFrame.TextRange.Text="Heading "&col

Next col

For row=2To tbl.Rows.Count

For col=1To tbl.Columns.Count

Next col

Next row

EndSub

' The following list includes the name and style for each of the available table styles.

' This list is undocumented, and was created using inspection. Any values could

' change in any version, and this list has only been tested for PowerPoint 2010:

' No Style, No Grid: {2D5ABB26-0587-4C30-8999-92F81FD0307C}

' Themed Style 1 - Accent 1: {3C2FFA5D-87B4-456A-9821-1D502468CF0F}

' Themed Style 1 - Accent 2: {284E427A-3D55-4303-BF80-6455036E1DE7}

' Themed Style 1 - Accent 3: {69C7853C-536D-4A76-A0AE-DD22124D55A5}

' Themed Style 1 - Accent 4: {775DCB02-9BB8-47FD-8907-85C794F793BA}

' Themed Style 1 - Accent 5: {35758FB7-9AC5-4552-8A53-C91805E547FA}

' Themed Style 1 - Accent 6: {08FB837D-C827-4EFA-A057-4D05807E0F7C}

' No Style, Table Grid: {5940675A-B579-460E-94D1-54222C63F5DA}

' Themed Style 2 - Accent 1: {D113A9D2-9D6B-4929-AA2D-F23B5EE8CBE7}

' Themed Style 2 - Accent 2: {18603FDC-E32A-4AB5-989C-0864C3EAD2B8}

' Themed Style 2 - Accent 3: {306799F8-075E-4A3A-A7F6-7FBC6576F1A4}

' Themed Style 2 - Accent 4: {E269D01E-BC32-4049-B463-5C60D7B0CCD2}

' Themed Style 2 - Accent 5: {327F97BB-C833-4FB7-BDE5-3F7075034690}

' Themed Style 2 - Accent 6: {638B1855-1B75-4FBE-930C-398BA8C253C6}

' Light Style 1: {9D7B26C5-4107-4FEC-AEDC-1716B250A1EF}

相关文档
最新文档