如何防止 Excel 加载项文件将对 R1C1/columns 的单元格引用更改为字母
How to prevent Excel Add-In file from changing cell references to R1C1/columns to letters
我创建了一个 Excel 加载项文件 (.xlam
) 以便能够将我的宏分发到我的部门。但是,当我在网上搜索答案时,我遇到了一个似乎找不到的问题。当我将加载项文件添加并安装到 Excel 时(通过 vbscript,如果这很重要)它会将 Excel 设置为 R1C1 模式,因此列是编号的而不是字母的。知道是什么原因造成的吗? vbscript 或加载项文件中的某些内容会触发此更改吗?在为 Excel 部署插件时,有没有人遇到过这种情况?我该如何预防?
试试看有没有改Application.ReferenceStyle = xlR1C1
如果没有,我会尝试插入
Dim previousRefStyle
previousRefStyle = Application.ReferenceStyle
Application.ReferenceStyle = xlA1
开始
Application.ReferenceStyle = previousRefStyle
所以用户将恢复原始设置
好的,看来我从 this link, where Post #10 on that forum thread points to Tip 2 in this link.
中找到了 实际 解决方案
步骤如下:
- 退出Excel(添加插件后)
- 单击“开始”> 运行 > 输入
Excel.exe /UnregServer
- 等待Excel再次打开
- 退出 Excel(再次),
- 单击“开始”> 运行 > 输入
Excel.exe /RegServer
这样做是清除(取消注册和重新注册)注册表。我希望这甚至可以为一个人节省我最终偶然发现 实际 解决方案而不仅仅是解决方法的谷歌搜索和论坛冲浪时间。
更新以包含 VBScript 实现示例:
要使用 VBScript 完成上述步骤(下面的脚本改编自 here),您可以使用类似的代码(当然是将路径更改为 Excel.exe)
Dim objFSO, objShell
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject ("WScript.shell")
objShell.Run "cmd /c ""C:\Program Files (x86)\Microsoft Office\Office14\excel.exe"" /unregserver && timeout /t 3 && tskill excel && ""C:\Program Files (x86)\Microsoft Office\Office14\excel.exe"" /regserver",1,True
Set objFSO = Nothing
Set objShell = Nothing
x=msgbox("Excel registry refreshed." ,0, "Registry Update")
wscript.quit
Disclaimer:
As @Rory points out below (see link in his comment), according to Microsoft's documentation those switches don't work from versions dated 2010 on. Though there are many instances of people citing that they have used this method with 2010 or later versions with success (see links in my comments) I figured I would just make whoever is reading this aware that it is a now-unsupported method by Microsoft. However, if it works for you and your situation (as many unsupported features of Microsoft often do) feel free to still use it.
我创建了一个 Excel 加载项文件 (.xlam
) 以便能够将我的宏分发到我的部门。但是,当我在网上搜索答案时,我遇到了一个似乎找不到的问题。当我将加载项文件添加并安装到 Excel 时(通过 vbscript,如果这很重要)它会将 Excel 设置为 R1C1 模式,因此列是编号的而不是字母的。知道是什么原因造成的吗? vbscript 或加载项文件中的某些内容会触发此更改吗?在为 Excel 部署插件时,有没有人遇到过这种情况?我该如何预防?
试试看有没有改Application.ReferenceStyle = xlR1C1
如果没有,我会尝试插入
Dim previousRefStyle
previousRefStyle = Application.ReferenceStyle
Application.ReferenceStyle = xlA1
开始
Application.ReferenceStyle = previousRefStyle
所以用户将恢复原始设置
好的,看来我从 this link, where Post #10 on that forum thread points to Tip 2 in this link.
中找到了 实际 解决方案步骤如下:
- 退出Excel(添加插件后)
- 单击“开始”> 运行 > 输入
Excel.exe /UnregServer
- 等待Excel再次打开
- 退出 Excel(再次),
- 单击“开始”> 运行 > 输入
Excel.exe /RegServer
这样做是清除(取消注册和重新注册)注册表。我希望这甚至可以为一个人节省我最终偶然发现 实际 解决方案而不仅仅是解决方法的谷歌搜索和论坛冲浪时间。
更新以包含 VBScript 实现示例:
要使用 VBScript 完成上述步骤(下面的脚本改编自 here),您可以使用类似的代码(当然是将路径更改为 Excel.exe)
Dim objFSO, objShell
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject ("WScript.shell")
objShell.Run "cmd /c ""C:\Program Files (x86)\Microsoft Office\Office14\excel.exe"" /unregserver && timeout /t 3 && tskill excel && ""C:\Program Files (x86)\Microsoft Office\Office14\excel.exe"" /regserver",1,True
Set objFSO = Nothing
Set objShell = Nothing
x=msgbox("Excel registry refreshed." ,0, "Registry Update")
wscript.quit
Disclaimer:
As @Rory points out below (see link in his comment), according to Microsoft's documentation those switches don't work from versions dated 2010 on. Though there are many instances of people citing that they have used this method with 2010 or later versions with success (see links in my comments) I figured I would just make whoever is reading this aware that it is a now-unsupported method by Microsoft. However, if it works for you and your situation (as many unsupported features of Microsoft often do) feel free to still use it.