newprogamer
Programmer
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
'**************************
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