Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why won't the excel file open 1

Status
Not open for further replies.

newprogamer

Programmer
Sep 22, 2004
107
US
Hello, I would like to open an excelworkbook (named strfile). The code will eventually open the workbook. But, before it opens the workbook it will display the error message that "MS Excel is waiing on another application to complete an OLE action". Does anyone know what is wrong with my code? Any help would be appreciated. Thanks!
'**************************

Private Sub OpenQuote()
'This sub will open the excel spreadsheets

On Error GoTo errhandler

Dim strfile As String 'The formal word document or the excel spreadsheets

'open excel spreadsheet
' Dim objExcelapp As Excel.Application 'this is Excel
Dim objExcelapp As Object 'This is Excel
Dim objExcelfile As Object 'These are the excel spreadsheets

strfile = DataGrid1.Columns("Name") 'full path to Excel file

Set objExcelapp = CreateObject("Excel.Application")

If objExcelapp Is Nothing Then 'If excel application is not there exit
MsgBox "Microsoft Excel is not found!", vbInformation, "ERROR"
Exit Sub

ElseIf strfile = "" Then '*******If Excel quote .xls is not there close
MsgBox " Excel quote does not exist!", vbInformation, "ERROR"
objExcelapp.Quit
Set objExcelapp = Nothing
Exit Sub

Else
'objExcelapp.Workbooks.Open Filename:=strfile 'open quote
Set objExcelfile = objExcelapp.Workbooks.Open(strfile) 'open spreadsheets

objExcelapp.Visible = True
Set objExcelapp = Nothing
Set objExcelfile = Nothing

End If
 
Hi newprogramer,

The first thing I see is the line objExcelapp.Visibile = True, this could be the culprit. I would place this line immediately after the Set objExcelapp = CreateObject("Excel.Application") line. This gives Excel time to load before getting hit with a request to open a file over a slow network connection. You may even introduce a DoEvents line after Set objExcelapp = CreateObject("Excel.Application") and the Set objExcelfile = objExcelapp.Workbooks.Open(strfile).

If none of this helps, check to see what add-ins you may be loading, they may be hindering Excel's startup. Finally if the file is coming across a network, move it to the hard drive and see if that alieviates the problem.

HTH
Todd
 
Thanks Todd,

I moved the line objExcelapp.Visibile = True like you suggested and it worked fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top