希望有人知道怎么做,我对VBA一点也不擅长。
我在我的机器上安装了Excel 2016 (64位)和Excel 2010 (32位)。这是因为我有一些更老的基于excel的工具,这些工具只在2010年才起作用。其中一个工具包含以下代码:
Start:
ThisWorkbook.Activate
strOutputsFilePath = gStrOutputsPath
strDMfilename = [DMFilePath]
'2. Refresh the PowerPivot model with the new data
'Create a new instance of excel
Application.StatusBar = "Opening a new instance of MS Excel"
Set appExcelApp = New Excel.Application
'Disconnect and Re-connect to the PowerPivot Add-in (in case it has been disconnected)
For Each comAddin In appExcelApp.COMAddIns
If comAddin.Description = "PowerPivot for Excel" Then
Set comAddinPPVT = comAddin
End If
Next
If Not comAddinPPVT Is Nothing Then
comAddinPPVT.Connect = False
comAddinPPVT.Connect = True
End If
'Apply the settings for the Excel application
With appExcelApp
.Visible = False
.ScreenUpdating = False
.DisplayAlerts = False
.EnableEvents = False
End With该应用程序应该做的是运行一个新的Excel 2010实例,并在其中打开某些文件。但是,在安装2016之后,New Excel.Application命令默认为打开Excel2016而不是2010年。这会导致PowerPivot加载项出现错误,因为数据模型之间不兼容。
问题是:是否有一种方法在VBA代码中指定我想要Excel 2010的实例?
尝试将Excel 2010默认设置在我的系统上,但是代码仍然打开,2016年出现错误:\
任何帮助都是非常感谢的!
谢谢
发布于 2017-07-05 06:57:59
要解决这个问题是不容易的。不建议或不支持在一台计算机上使用两个不同版本和两个不同的Excel位值变体。这是相当不寻常的,所以没有开箱即用的修复。
我的建议是,如果您不希望Excel 2016 (64位)干扰Excel 2013 (32位)的内容,请不要在同一台计算机上安装这两个版本。
考虑使用虚拟机(VM)运行一个版本,并将另一个版本保留在主计算机上。这将确保他们不会干涉。
发布于 2017-07-05 09:30:35
使用Shell函数怎么样?
Private Sub OpenExcelInstance(version as string)
Dim path As String
Dim appInstance As Variant
Select Case version
Case "Excel 2010"
path = "C:\Program Files (x86)\blablabla\Excel.exe" 'path to 32bit 2010 executable
Case "Excel 2016"
path = "C:\Program Files\blablabla\Excel.exe" 'path to 64 bit 2016 executable.
Case default
Exit sub
End Select
appInstance = Shell(path, 1)
'GetObject function here.
End Sub但是,您不能对这个appInstance进行编码--它是一个由shell命令返回的整数。
之后可以使用GetObject从它中获取应用程序实例,但是我没有深入研究这个问题,因为我遇到了有文档的问题这里,并且它有一个非常有问题的这里 (不是真正的未回答的)。
https://stackoverflow.com/questions/44918842
复制相似问题