在已经有ThisDocument的情况下再加一个新的
时间: 2024-02-29 08:53:22 浏览: 21
在已经有 ThisDocument 的情况下,你可以使用 Set 语句将一个新的 Document 对象赋值给 ThisDocument,比如:
```
Sub AddNewThisDocument()
Set ThisDocument = Documents.Add
End Sub
```
这个代码会创建一个新的文档,并将它赋值给 ThisDocument 对象,这样你就可以在 Word 对象中同时访问两个文档了。注意,这个代码应该在 ThisDocument 对象已经存在的情况下运行,否则会出错。
相关问题
一个word文档只能有一个ThisDocument吗
是的,一个 Word 文档只能有一个 ThisDocument 对象。ThisDocument 对象是一个 Document 类型的对象,它代表了当前打开的文档,在 VBA 代码中可以通过 ThisDocument 对象来访问文档的内容、样式等。在一个文档中只能有一个 ThisDocument 对象,如果你尝试创建一个新的 ThisDocument 对象,它会覆盖掉原有的 ThisDocument 对象。
在word的对象里面怎么新建一个ThisDocument
要在 Word 的对象中新建一个 ThisDocument,可以按照以下步骤操作:
1. 打开 Microsoft Word,创建一个新的文档。
2. 在菜单栏上选择“视图”,然后选择“宏”。
3. 在“宏”对话框中,输入一个宏的名称,比如“NewThisDocument”,并点击“创建”按钮。
4. 在弹出的 Microsoft Visual Basic for Applications 窗口中,输入以下代码:
```
Sub NewThisDocument()
Set ThisDocument = ActiveDocument
End Sub
```
5. 点击“保存”按钮保存宏,然后关闭 Microsoft Visual Basic for Applications 窗口。
6. 现在你可以在 Word 对象中使用 ThisDocument 对象了,比如通过 VBA 代码访问文档中的内容、样式等。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)