如何使用 Excel 宏打开 dotx 文件

How do I open a dotx file with Excel Macro

我想用这个Word模板打开一个新文档

但是我的代码在“编辑模式”下打开文件

Dim Paragraphe As Object, WordApp As Object, WordDoc As Object
File = "C:\Source\File.dotx"
'Word session creation
Set WordApp = CreateObject("Word.Application")
'word will be closed while running
WordApp.Visible = True
'open the .doc file
Set WordDoc = WordApp.Documents.Open(File)

您需要使用 .Add 方法而不是 .Open 并指定 Template 参数。

Set WordDoc = WordApp.Documents.Add(Template:=File)

请记住,这个新文档在创建时没有文件名。

https://docs.microsoft.com/en-us/office/vba/api/word.documents.add