java在文档末尾添加_如何在打开表单后将子文件添加到Word文档的末尾?

该博客讨论了如何通过VBA宏在Word文档打开时自动将子文档添加到文档末尾的问题。作者遇到的挑战是,在Document_Open事件中直接操作光标未生效,导致子文档被添加到文档开头。为解决此问题,博客提供了一个经过编辑的代码示例,通过在用户输入表单中调用函数,先将光标定位到文档末尾,然后逐个添加子文档。
摘要由CSDN通过智能技术生成

我'm trying to write a macro that adds subdocuments to the end of a Word document when the Word document is opened. The document in question already has some text in it, so before running the macro I' d喜欢将光标移动到文档的末尾 . 我可以使用代码实现这一点: Selection.EndKey Unit:=wdStory 在打开文档后运行宏时工作正常,但是如果我在使用Sub打开文档后立即运行宏:

Private Sub Document_Open()

Selection.EndKey Unit:=wdStory

'Add subdocuments based on user input to a form

'(See edit below)

End Sub

在ThisDocument对象中,子文档添加在文档的开头 . 这可能是因为光标还没有出现所以 Selection 还没有't '存在 .

如何在文档打开时运行我的宏,但是将子文档添加到文档的末尾?

我先尝试写出一个空格,使光标产生但没有变化......

对替代方法的任何建议也欢迎 .

编辑:ThisDocument中的此代码:

Private Sub Document_Open()

CreateWorkbook.Show

End Sub

调用表单CreateWorkbook,点击子按钮:

Private Sub GenerateButton_Click()

Dim i As Integer

Dim rng As Word.Range

Set rng = ActiveDocument.Content

rng.Collapse wdCollapseEnd

'ModulesListBox is a user input box that is a list of paths to the subdocuments

For i = 0 To ModulesListBox.ListCount - 1

docpath = ModulesListBox.List(i)

rng.Subdocuments.AddFromFile docpath

Next i

End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值