新手求救——VB如何获取插入的BuildingBlock内容并删除

SharonSh 2013-09-06 05:43:42
大家好,我是刚接触word开发与VBA的菜鸟,手头上有个关于改写现有模板的紧急任务,目的是把原来模板中重复调用的内容用Buildingblock的形式存放并在宏中进行调用。
原来代码如下:
Public MyCollapseArry(100) As Table
Public CollapseNumber As Integer
...
Sub Insert_CollapsePart(CollapseTitle As String, CurrentCollapseStyle As String)

Dim tblNew As Table
Dim PreWidth
Dim IfinTable As Boolean
Dim TableStyle
Dim Current_CollapseTitle As String

IfinTable = Selection.Information(wdWithInTable)

If IfinTable = True Then
PreWidth = Selection.Cells.Width
TableStyle = Selection.Tables(1).Style

Selection.TypeParagraph
Set tblNew = ActiveDocument.Tables.Add(Selection.Range, 2, 2)

If CollapseTitle = "" Then
Current_CollapseTitle = "Input content summary Here"
Else
Current_CollapseTitle = CollapseTitle
End If

With tblNew
.Style = CurrentCollapseStyle
.Columns(1).Width = InchesToPoints(0.5)
.Columns(2).Width = PreWidth - InchesToPoints(0.7)

.Cell(1, 1).Range.InlineShapes.AddPicture FileName:=ThisDocument.Path & "\images\Small_White_Collapse.png", LinkToFile _
:=False, SaveWithDocument:=True
.Cell(1, 2).Range.InsertAfter Current_CollapseTitle
.Cell(1, 2).Shading.BackgroundPatternColor = wdColorGray15
.Cell(1, 2).Range.Style = ActiveDocument.Styles("CollapseTitle")

.Cell(2, 2).Shading.BackgroundPatternColor = wdColorGray15
.Cell(2, 2).Range.InsertAfter "Input content that you want to collapse"
.Cell(2, 2).Range.Style = ActiveDocument.Styles("GWT_CollapseContent")

End With

Set MyCollapseArry(CollapseNumber) = tblNew
CollapseNumber = CollapseNumber + 1

Else
MsgBox ("You can only add collapse content into Input content or Input Additional information part of the page, or embed into another Collapse part.")
End If

End Sub

现在我已经在word菜单栏中创建了buildingblock(InsertExpandCollapseSetion),category为"MyTask",类型为“QuickParts",并且能够顺利插入这些buildingblock到文档中,代码如下
Public objTemplate As Template
Public objBB As BuildingBlock
Sub InsertExpandCollapseSection
' Set the template to store the building block
Set objTemplate = ActiveDocument.AttachedTemplate

' Access the building block through the type and category
Set objBB = objTemplate.BuildingBlockTypes(wdTypeQuickParts).Categories("MyTask").BuildingBlocks("InsertExpandCollapseSection")
' Insert the building block into the document
objBB.Insert Selection.Range
Set MyCollapseArry(CollapseNumber) = ?
CollapseNumber = CollapseNumber + 1
End Sub

但还有个宏是撤销之前插入的buildingblock(InsertExpandCollapseSection),类似于word本身的undo功能,我大概知道原来代码中的数组MyCollapseArry(CollapseNumber)就是作为中间变量去存储插入的内容,但不知道改为buildingblock后怎么给这个数组赋值,代码该怎么实现?主要不知道该用什么类型的数组以及如何取得插入的buildingblock的内容,请大虾们指点,小女子感激不尽!
...全文
66 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
SharonSh 2013-09-09
  • 打赏
  • 举报
回复
从别的渠道得知无法获得buildingblock插入的内容作为数组存储,加上在CSDN论坛两个不同的入口问这个问题几天都没人回答,所以关贴

5,139

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 Office开发/ VBA
社区管理员
  • Office开发/ VBA社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧