将 Excel 模板 (xltx) 作为 Excel 模板而不是工作簿打开
Opening an Excel Template (xltx) as an Excel Template not a workbook
我正在尝试编写一行代码来打开 excel 模板 (xltx) 文件作为 excel 模板文件而不是新工作簿。
我只是想让用户查看和编辑他们在我们网络上的库文件夹中的模板。
但是我尝试过的所有操作都会打开一个新的工作簿而不是模板。
我试过互操作:
Workbooks.Open(selectedxltxFile, Missing.Value, Missing.Value, Excel.XlFileFormat.xlOpenXMLTemplate, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
还有Process.Start方法:
System.Diagnostics.Process.Start(@"C:\MYTemnplate.xltx")
这有可能吗,还是我找错树了?
Workbooks.Open(Filename: @"C:\MYTemnplate.xltx", Editable: true);
我在任何地方都找不到这个。当所有其他方法都失败时(这不太好)记录一个包含您要完成的操作的宏,然后查看生成的 VBA.
来自the docs:
Editable
Type: System.Object
Optional Object. If the file is a Microsoft Excel 4.0 add-in, this argument is True to open the add-in so that it’s a visible window. If this argument is False or omitted, the add-in is opened as hidden, and it cannot be unhidden. This option doesn't apply to add-ins created in Microsoft Excel 5.0 or later. If the file is an Excel template, use True to open the specified template for editing or False to open a new workbook based on the specified template. The default value is False.
换句话说,这个参数可以根据上下文表示不同的意思,其中 none 是直观的。如果指定 Editable: false
,则会根据模板打开一个新工作簿。它是可编辑的吗?是的
我正在尝试编写一行代码来打开 excel 模板 (xltx) 文件作为 excel 模板文件而不是新工作簿。
我只是想让用户查看和编辑他们在我们网络上的库文件夹中的模板。
但是我尝试过的所有操作都会打开一个新的工作簿而不是模板。
我试过互操作:
Workbooks.Open(selectedxltxFile, Missing.Value, Missing.Value, Excel.XlFileFormat.xlOpenXMLTemplate, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
还有Process.Start方法:
System.Diagnostics.Process.Start(@"C:\MYTemnplate.xltx")
这有可能吗,还是我找错树了?
Workbooks.Open(Filename: @"C:\MYTemnplate.xltx", Editable: true);
我在任何地方都找不到这个。当所有其他方法都失败时(这不太好)记录一个包含您要完成的操作的宏,然后查看生成的 VBA.
来自the docs:
Editable
Type: System.Object
Optional Object. If the file is a Microsoft Excel 4.0 add-in, this argument is True to open the add-in so that it’s a visible window. If this argument is False or omitted, the add-in is opened as hidden, and it cannot be unhidden. This option doesn't apply to add-ins created in Microsoft Excel 5.0 or later. If the file is an Excel template, use True to open the specified template for editing or False to open a new workbook based on the specified template. The default value is False.
换句话说,这个参数可以根据上下文表示不同的意思,其中 none 是直观的。如果指定 Editable: false
,则会根据模板打开一个新工作簿。它是可编辑的吗?是的