在 Word 2007 上使用 VBA 复制节

发布于 2024-11-27 16:07:17 字数 148 浏览 1 评论 0原文

我有一个文档模板,其中有一段文本包含标题和列表。当我编辑此部分时,我希望 Word 在下面创建一个新部分。因此编辑该部分就像“添加按钮”一样。这可行吗? 目前,我正在尝试使用构建块,并且我设法插入这个新部分,但我不知道在编辑当前现有部分时如何执行此操作以及如何在当前部分之后插入它。

I have a document template that has a section of text that contains a Header and a List. When I edit this section I want Word to create a new one underneath. So editing the section works like a "Add button". Is this feasible?
Currently I'm trying to use Building Blocks and with those I manage to insert this new section but I don't know how to do it when editing a currently existing section and how to insert it after the current section.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

森林很绿却致人迷途 2024-12-04 16:07:18

快速搜索后,似乎无法监视事件,例如 keypress (或等效项)、onclick 或任何可能发生的事件当用户向部分添加文本时触发。
因此,据我所知,当用户添加文本时,您无法自动触发新部分。

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

After a quick search, it seems like there is no way to monitor events like keypress (or equivalent), onclick or any event that could be triggered when a user is adding text to a section.
Thus, as far as i can see, you can't automatically trigger a new section when a user is adding text.

What you can do is adding a button in a menu/in the ribbon (depending on the version you are using) to add a new section.

一抹淡然 2024-12-04 16:07:18
  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

Sub ButtonAction1()

'你的代码

结束子

我希望这对你有帮助
它在Word菜单上创建一个按钮

  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

Sub ButtonAction1()

'your code

end sub

I hope this helps you
It creates a button on word menu

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文