GetObject(, "Excel.Application") takes forever, sometimes

GetObject(, "Excel.Application") takes forever, sometimes

bwangNYAKX
Contributor Contributor
852 Views
3 Replies
Message 1 of 4

GetObject(, "Excel.Application") takes forever, sometimes

bwangNYAKX
Contributor
Contributor

Hi all,

 

I am writing a code that needs to extract some value from excel. My code worked fine but today all in a sudden when I run it, the code started to get stucked in getobject function forever. No any error, it just seems to me that the code is running something countless times...  This happened me two days ago but all in a sudden it was gone. Now it came back. What can I do?     FYI, 1. CreateObject("Excel.Application") works fine, just takes so long

 

Dim oexcelApp As Object
                       On Error Resume Next
                                       Set oexcelApp = GetObject(, "Excel.Application")
                                     If Err Then
                                                                         Err.Clear
                                                                        Set oexcelApp = CreateObject("Excel.Application")
                                                                                                                     If Err Then
                                                                                                                                  MsgBox "Cannot access excel."
                                                                                                                                   Exit Sub
                                                                                                                     End If
                                       End If

0 Likes
853 Views
3 Replies
Replies (3)
Message 2 of 4

robertast
Collaborator
Collaborator

In the 2021.1 update, they promised to improve communication with Excel. The beta version has already appeared in skaro and will be available publicly.

0 Likes
Message 3 of 4

sgodonVEAP9
Contributor
Contributor

I have the exact same problem here.. I have this very simple code that copies excel values:

 

Dim xlApp
Set xlApp = GetObject("", "Excel.Application")
Dim xlWorkbook As Object
Set xlWorkbook = x1App.Workbooks.Open("C:\Users\ac rainville\Desktop\TEST\SHUMAKER.xlsm")
With xlWorkbook.Worksheets(3)
.Range("A1:F77").Copy
End With

 

It takes around 10 to 12 seconds only to run this.. Any ideas how to improve that? thanks!

0 Likes
Message 4 of 4

A.Acheson
Mentor
Mentor

I tested this and it should be in the region of 1.8secs to open visible the excel sheet and select the cells. Your code has an error on this line “x1App.Workbooks.Open” for some reason the “l” is actually the number “1”

 

As for slow opening, try and open excel manually and see if it opens quickly. If you have a lot of templates/files opening on startup this morning guy be a reason. After that check off any addins in the excel application, one of them could be causing a delay, I have found the 3D mouse was at fault causing slow start up speed. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes