2011-08-02 26 views
0

我有一个文档模板,其中包含一个包含Header和List的文本部分。当我编辑这个部分时,我希望Word在下面创建一个新的。所以编辑该部分就像一个“添加按钮”。这是可行的吗? 目前我正在尝试使用Building Block和那些我设法插入这个新的部分,但我不知道如何编辑当前存在的部分以及如何在当前部分之后插入它。在Word 2007中复制使用VBA的部分

+0

问题是*编辑部分*会在每次添加新角色时发生。你能更清楚你想做什么吗?解释一下为什么?你可以在菜单/功能区添加一个按钮来添加一个区域... – JMax

+0

对不起,我没有让自己很清楚。有问题的模板旨在编写会议纪要,并由包含标题和项目符号列表的几个部分组成。我的想法是,当您将字符添加到空白部分(只有占位符字符或没有任何内容的部分)时,会添加新部分。这对于撰写会议纪要的人来说总是有一个新的部分可以写入。 – lamelas

回答

1

快速搜索之后,它好像有没有办法监控事件keypress(或同等学历),onclick或可以当用户添加文本到部分被触发的任何事件。
因此,据我所见,当用户添加文本时,不能自动触发新的部分。

您可以做的是在功能区(取决于您使用的版本)中的菜单/添加按钮以添加新的部分。

+0

这将工作。如何在所有其他部分之后添加新部分?我不知道该怎么做。对不起,我对VBA的知识非常非常基本。 – lamelas

+0

如果你的VBA非常基础,我建议你看看一些Tutos,以便更熟悉Word VBA(这不是最简单的),并且仔细想想你将如何处理你的案例。例如,你将不得不找到文档的末尾>>见[这里](http://vbadud.blogspot.com/2008/03/identify-end-of-document-using-word-vba.html)并复制粘贴你的“模型部分”(你会在哪里保留它?)。你应该尝试一下,回头看看你建立的代码,以寻求一些你无法处理的东西的帮助。 – JMax

+0

非常感谢。我添加了一个按钮,并设法使用该网站的一些经验教训。 :) – lamelas

0
Dim cbToolBar As CommandBar 
    Dim cbMenuBar As CommandBarPopup 
    Dim cbSuBMnu1 As CommandBarButton 
    Dim strToolBar As String 
    Dim iCount As Integer 

    ' Replace "My Toolbar" with a name 
    ' you want to use for your toolbar. 
    strToolBar = "Macro Toolbar" 

    ' If a toolbar of this name already exists, 
    ' append a number to the end of name to 
    ' differentiate one from the other. 

    ' Create and display the Toolbar. 
    Set cbToolBar = CommandBars.Add(Name:=strToolBar, _ 
    Position:=msoBarFloating) 
    cbToolBar.Visible = True 

    ' Create Main PopUp Menu on Toolbar. 
    Set cbMenuBar = cbToolBar.Controls.Add(Type:=msoControlPopup) 
    cbMenuBar.Caption = "Macros" 

    ' Add a Menu Button and a Popup 
    ' Menu to the "Main PopUp Menu." 
    With cbMenuBar.Controls 

    Set cbSuBMnu1 = .Add(Type:=msoControlButton) 

    End With 

    ' Set properties for the sub 

    With cbSuBMnu1 
    .Caption = "Change Styles" 
    .Style = msoButtonCaption 
    .OnAction = "ButtonAction1" ' <- Macro to run when clicked. 
    .FaceId = 150 

    End With 

     'cbSuBMnu1.OnAction = "Tag" 

     End Sub 

子ButtonAction1()

“你的代码

末次

我希望这可以帮助你 它创建Word菜单上的按钮