GetObject不适用于Excel 2016 [英] GetObject does not work with Excel 2016

查看:605
本文介绍了GetObject不适用于Excel 2016的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在我的Windows 10 64计算机上正常运行,运行Visual Basic 2013和Excel 2010


        Dim oExcel As Excel.Workbook = Nothing


        oExcel = GetObject(路径+文件名)



        oExcel.Application.Visible = True



        oExcel.Windows(1).Visible = True



但是,当我在安装Office 2016后运行相同的代码时,文件名工作簿没有打开,它会打开两个Excel窗口,这些窗口是空白的(没有显示工作表)并且没有响应。他们必须在Task
Manager中结束任务。 



代码抛出一条错误消息,指出索引已脱离范围,这是由于Windows.Count为0。



在运行代码之前打开文件名工作簿时,GetObject会连接到工作簿的实例,它可以继续工作簿操作(虽然,有些变得非常慢)。



我已添加到我的项目中Microsoft Office 16和Microsoft Excel 16引用,删除Office 14和Excel 16以前的引用。 


我需要帮助来解决这个已经成为我的大瓶颈的问题。


非常感谢。





$

解决方案


使用你的代码,我得到同样的错误。


修改你的代码:添加

shell方法
运行Excel .exe然后获取实例


Shell(" C:\Program Files(x86)\ Microsoft Office \ OfficeOff \ _Excel.exe",


            AppWinStyle.MinimizedFocus)


 


例如


        Dim oExcel As Excel.Workbook = Nothing


        Shell(" C:\Program Files(x86)\ Microsoft Office \ Office16 \ Excel .exe",


            AppWinStyle.MinimizedFocus)


        oExcel = GetObject(" C:\Users\Administrator \Desktop\test.xlsx" )


        oExcel.Application.Visible = True


        oExcel.Windows(1).Visible = True


< p style ="margin:0in; margin-bottom:.0001pt">  


或另一种打开工作簿的简单方法


        Dim xlApp As Object


        xlApp = CreateObject(" Excel.Application")


        xlApp.Visible = True


        xlApp.Application.Workbooks.Open(" C:\Users \Administrator \Desktop\test.xlsx ")


&NBSP;


The following code works fine on my Windows 10 64 computer, running Visual Basic 2013 and Excel 2010

        Dim oExcel As Excel.Workbook = Nothing

        oExcel = GetObject(path + filename)

        oExcel.Application.Visible = True

        oExcel.Windows(1).Visible = True

However, when I run the same code after having installed Office 2016, when the filename workbook is not opened, it opens two Excel windows, which are blank  (no worksheets are displayed) and unresponsive. They have to be closed ending the task in Task Manager. 

The code throws an error message saying index out of range, which is due to Windows.Count being 0.

When the filename workbook is open before running the code, the GetObject does connect with the instance of the workbook and it can proceed with the workbook operations (although, some become very slow).

I have added to my project the Microsoft Office 16 and Microsoft Excel 16 references, removing the Office 14 and Excel 16 previous references. 

Please I need help to solve this problem that has become a big bottleneck for me.

Many thanks.

解决方案

Hi,

Using your code, I get the same error.

Modify your code: add shell method to run Excel.exe then get the instance

Shell("C:\Program Files (x86)\Microsoft Office\Office16\Excel.exe",

            AppWinStyle.MinimizedFocus)

 

E.g.

        Dim oExcel As Excel.Workbook = Nothing

        Shell("C:\Program Files (x86)\Microsoft Office\Office16\Excel.exe",

            AppWinStyle.MinimizedFocus)

        oExcel = GetObject("C:\Users\Administrator\Desktop\test.xlsx")

        oExcel.Application.Visible = True

        oExcel.Windows(1).Visible = True

 

Or another simple method to open workbook

        Dim xlApp As Object

        xlApp = CreateObject("Excel.Application")

        xlApp.Visible = True

        xlApp.Application.Workbooks.Open("C:\Users\Administrator\Desktop\test.xlsx")

 


这篇关于GetObject不适用于Excel 2016的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆