|
-
Mar 16th, 2006, 06:15 AM
#1
Thread Starter
Fanatic Member
Excel QueryInterface problem
Guys,
I am getting this error when trying to set DisplayAlerts in excel to false. This has been working fine for months, why would it suddenly stop working ? It still creates the excel document OK after this error.
Thanks
Bob
Error: QueryInterface for interface Microsoft.Office.Interop.Excel._Application failed.
Err No:13Stack Trace:
at Microsoft.Office.Interop.Excel.ApplicationClass.set_DisplayAlerts(Boolean RHS)
This is my code that gets Excel....
VB Code:
Dim xl As Excel.Application
Try
Try
xl = GetObject(, "Excel.Application")
Catch ex As Exception
xl = New Excel.Application
End Try
Dim wkbk As Excel.Workbook
Dim wkst As Excel.Worksheet
xl.DisplayAlerts = False 'FAILS HERE ####
xl.Visible = False
Dim docpath As String
wkbk = xl.Workbooks.Open(TemplateLocation)
wkst = wkbk.Sheets(1)
"I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings
-
Mar 16th, 2006, 02:08 PM
#2
Addicted Member
Re: Excel QueryInterface problem
1. Make sure you have a reference to the Microsoft Office/Excel dll inside
of your solution.
2. Im not sure how your telling what excel document to get, but
make sure its there.
Using Framework 1.1, VB.Net 2003 unless I
state otherwise 
-
Mar 16th, 2006, 02:33 PM
#3
Addicted Member
Re: Excel QueryInterface problem
Private _strFile As String = String.Empty
Public Property strFile() As String
Get
Return _strFile
End Get
Set(ByVal Value As String)
_strFile = Value
End Set
End Property
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
'close/exit the main form
Me.Close()
End Sub
Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
Try
'user wants to open a excel file
subOpenExcel()
Catch ex As Exception
'notify user if error
MessageBox.Show(ex.Message.ToString.Trim)
End Try
End Sub
Private Sub subOpenExcel()
Try
'Set the file name
Me.subSetFileName()
'Open the excel document
If Me.strFile.ToString.Trim.Length > 2 Then
subOpenFile()
Else
'select a file
MessageBox.Show("You need to select an Excel file.")
End If
Catch ex As Exception
'if error notify the user
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub subSetFileName()
Try
'filter which files to open
Me.OpenFileDialog1.Filter = "Excel Docs (*.xls)|*.xls|All files|*.*"
'if user selects a file then set the selected filename
If Me.OpenFileDialog1.ShowDialog = DialogResult.OK Then
Me.strFile = Me.OpenFileDialog1.FileName.ToString.Trim
End If
Catch ex As Exception
'if error notify the user
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub subOpenFile()
Try
Dim oExcel As New Excel.Application
Dim oWorkBook As Excel.Workbook
Dim oWorkSheet As Excel.Worksheet
oExcel.DisplayAlerts = True
oExcel.Visible = True
oWorkBook = oExcel.Workbooks.Open(Me.strFile)
'oWorkSheet = oWorkBook.Worksheets("myWorkSheet")
'oWorkSheet.Activate()
Catch ex As Exception
'if error notify the user
MessageBox.Show(ex.Message)
End Try
End Sub
Using Framework 1.1, VB.Net 2003 unless I
state otherwise 
-
Mar 17th, 2006, 08:28 AM
#4
Thread Starter
Fanatic Member
Re: Excel QueryInterface problem
Thanks Bgard,
1 - I have got a reference set correctly, if it wasn't there, the code would fail on xl = GetObject(, "Excel.Application")
2 - Yup, the document is there, always has been.
Bob
"I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|