Component request Pending (1 Viewer)

kirkm

Registered User.
Local time
Tomorrow, 02:37
Joined
Oct 30, 2008
Messages
1,257
I seem to be stuck in a loop with:

This action cannot be completed because the other
application is busy. Choose 'Switch To' to activate
the busy application and correct the problem.

I can only Switch To or Retry neither give me back control.
Code:
Sub Main()
Dim ExcelFile As String
Dim objExcel As Object, wb As Object
ExcelFile = getExcel  'returns Excel filename
If ExcelFile > "" Then
Set objExcel = CreateObject("excel.application")
Set wb = objExcel.workbooks.Open(ExcelFile)
objExcel.Worksheets("Sheet1").Activate

With objExcel
Debug.Print .cells(1, 1)
.cells(1, 1) = "test"
End With
End If
objExcel.displayalerts = False
objExcel.Save
objExcel.quit
End Sub
The aim is to read and write to Sheet1. I was attempting to get the code working when this Dialog appeared. Perhaps someone can see what the probelm is ?
 

June7

AWF VIP
Local time
Today, 06:37
Joined
Mar 9, 2014
Messages
5,470
Show your code for the getExcel procedure. I substituted this with a hard-coded file path/name. I don't get the error, code works.

Code would be easier to read and interpret with indentation.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:37
Joined
Oct 29, 2018
Messages
21,467
Hi. Just curious, did your code work at least once and then you started getting the error when you tried it again?
 

kirkm

Registered User.
Local time
Tomorrow, 02:37
Joined
Oct 30, 2008
Messages
1,257
I'm in the wrong forum, sorry...but may not matter that much but this is VB6. It was working without error until I added the Save and Quit commands.
June: When this crashed I lost that getExcel Function and a whole lot of API I'd pasted in. But it just returned the Excel filename/path.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:37
Joined
May 7, 2009
Messages
19,230
you Save the Workbook Object not the Excel.Application
 

kirkm

Registered User.
Local time
Tomorrow, 02:37
Joined
Oct 30, 2008
Messages
1,257
Understood arne, but I can't get the syntax right. The problem seems with the last 3 lines.
' wb.DisplayAlerts = False
wb.Save
objExcel.Quit

I have to rem out the Display alerts or it errors.
But the result is not good. The workbook won't open without a "locked for editing" error and the data in it has not changed.
 

June7

AWF VIP
Local time
Today, 06:37
Joined
Mar 9, 2014
Messages
5,470
If you don't have the function code, how can it return file path?

Since code works in Access VBA, issue is with that function and/or the VB6 environment.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:37
Joined
May 7, 2009
Messages
19,230
DisplayAlert is a method of objExcel:

objExcel.DisplayAlerts = False
 

kirkm

Registered User.
Local time
Tomorrow, 02:37
Joined
Oct 30, 2008
Messages
1,257
> If you don't have the function code, how can it return file path?
I wasn't saved so was lost after the crash. Since resurrected -
Code:
Function getExcel() As String
    Dim CommonDialog1 As Object
    Set CommonDialog1 = CreateObject("MSComDlg.CommonDialog")
    CommonDialog1.Filter = "Excel Files *.xls,*.xlsx"
    CommonDialog1.DialogTitle = "Select File"
    CommonDialog1.ShowOpen
    getExcel = CommonDialog1.fileName
    Set CommonDialog1 = Nothing
End Function
 

Gasman

Enthusiastic Amateur
Local time
Today, 15:37
Joined
Sep 21, 2011
Messages
14,262
You need to save a little more often, before running code? 😀
 

kirkm

Registered User.
Local time
Tomorrow, 02:37
Joined
Oct 30, 2008
Messages
1,257
I Know I know! Every time it crashes I'm reminded of that !
But I have a text screen capture tool, so sometimes don't lose everything .
 

Users who are viewing this thread

Top Bottom