Advertisement

12.28.2007 at 03:40PM PST, ID: 23048319
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

Errors with Microsoft.Interop.Excel on all Workstations except the one the application was written on.

Asked by sinisterJeepFreak in .NET, Visual Basic Programming, Development Software

Tags: , , , , ,

I created a Time Sheet application that modifies local copies of Excel templates. On my computer, it works without any problems. However, when the application is ran from any other computer it throws the following error. If anyone has any experience with this, or would have an idea how to fix this, or anything else you might see wrong with it please let me know! It would be greatly appreciated. If you have any questions please let me know!  Thank you.
Here is the error that the end users receiev when they run the application on their workstations (again it works on mine):
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
System.InvalidCastException: QueryInterface for interface Microsoft.Office.Interop.Excel._Application failed.
   at Microsoft.Office.Interop.Excel.ApplicationClass.get_Application()
   at Timesheets.frmtsheet.cmdOK_Click_1(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** Loaded Assemblies **************

mscorlib

    Assembly Version: 1.0.5000.0

    Win32 Version: 1.1.4322.2407

    CodeBase: file:///c:/windows/microsoft.net/framework/v1.1.4322/mscorlib.dll
----------------------------------------
Timesheets

    Assembly Version: 1.0.2918.26160

    Win32 Version: 1.0.2918.26160

    CodeBase: file:///C:/Program%20Files/toav/TSheet/Timesheets.exe
----------------------------------------
System.Windows.Forms

    Assembly Version: 1.0.5000.0

    Win32 Version: 1.1.4322.2032

    CodeBase: file:///c:/windows/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System

    Assembly Version: 1.0.5000.0

    Win32 Version: 1.1.4322.2407

    CodeBase: file:///c:/windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
System.Drawing

    Assembly Version: 1.0.5000.0

    Win32 Version: 1.1.4322.2032

    CodeBase: file:///c:/windows/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
Microsoft.VisualBasic

    Assembly Version: 7.0.5000.0

    Win32 Version: 7.10.6001.4

    CodeBase: file:///c:/windows/assembly/gac/microsoft.visualbasic/7.0.5000.0__b03f5f7f11d50a3a/microsoft.visualbasic.dll
----------------------------------------
System.DirectoryServices

    Assembly Version: 1.0.5000.0

    Win32 Version: 1.1.4322.2032

    CodeBase: file:///c:/windows/assembly/gac/system.directoryservices/1.0.5000.0__b03f5f7f11d50a3a/system.directoryservices.dll

----------------------------------------
System.Xml

    Assembly Version: 1.0.5000.0

    Win32 Version: 1.1.4322.2032

    CodeBase: file:///c:/windows/assembly/gac/system.xml/1.0.5000.0__b77a5c561934e089/system.xml.dll
----------------------------------------
Microsoft.Office.Interop.Excel

    Assembly Version: 12.0.0.0

    Win32 Version: 12.0.4518.1014

    CodeBase: file:///c:/windows/assembly/gac/microsoft.office.interop.excel/12.0.0.0__71e9bce111e9429c/microsoft.office.interop.excel.dll
----------------------------------------
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
Private Sub cmdOK_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click 'The main event: connects to Timesheet Templates and fills in all of the info
        Dim i = 0, x = 0
        Dim strTimeSheet, strWorkSheetName, filename, fancy, strCell1, strCell2 As String
        Dim sbExcelData As System.Text.StringBuilder
        Dim aExcel As New Excel.Application
        Dim aWorkbook As Excel.Workbook
        Dim aWorkSheet As Excel.Worksheet
        Dim aWorkRange As Excel.Range
        Dim aProcesses() As Process = Process.GetProcesses
        Dim checkDate As Date = calTimesheet.SelectionStart.Date
        Dim endcheck As Date = checkDate.AddDays(14).Date
 
        Me.Hide()
        aExcel.Application.SheetsInNewWorkbook = 1
 
        Select Case trigger
            Case 1
                path1 = "C:\Documents and Settings\" & username & "\TimeSheet\Templates\980Hourly.xls"
                path2 = "C:\Documents and Settings\" & username & "\Timesheet\980Hourly.xls"
                strTimeSheet = "980Hourly.xls"
                strWorkSheetName = "980Hourly"
            Case 2
                path1 = "C:\Documents and Settings\" & username & "\TimeSheet\Templates\Salary.xls"
                path2 = "C:\Documents and Settings\" & username & "\Timesheet\Salary.xls"
                strTimeSheet = "Salary.xls"
                strWorkSheetName = "Salaried"
            Case 3
                path1 = "C:\Documents and Settings\" & username & "\TimeSheet\Templates\Standard.xls"
                path2 = "C:\Documents and Settings\" & username & "\Timesheet\Standard.xls"
                strTimeSheet = "Standard.xls"
                strWorkSheetName = "Standard"
        End Select
 
        Try
            ' Ensure that the target does not exist.
            If System.IO.File.Exists(path2) Then
                System.IO.File.Delete(path2)
            End If
            ' Copy the file.
            'System.IO.File.Copy(path1, path2)
        Catch
            Call killprocesses()
        End Try
 
        aExcel.Visible = False
 
        Try
            aWorkbook = aExcel.Workbooks.Open(path1)
            aWorkSheet = CType(aWorkbook.Sheets(strWorkSheetName), Microsoft.Office.Interop.Excel.Worksheet)
            aWorkSheet.Activate()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Error!")
        End Try
 
        'The Following will fill the information in the timesheet for the User
 
        Select Case trigger
            Case 1 '9/80 Hourly
                If Switch = False Then
                    aWorkSheet.Cells(41, 1) = txtEmpNum.Text
                    aWorkSheet.Cells(43, 4) = txtName.Text
                End If
 
                Do Until checkDate.Date = endcheck.Date 'This will cycle through each date starting from the Calendar objects Start Selection to the End Selection
                    Do Until x = 12 'Will look through all 12 of the Holidays and see if one of the days in checkDate is a Holiday
                        If checkDate.Date = arDate(x).Date Then 'If it is then it will Add "Holiday" to the cell above the date in the spreadsheet and gray out the day
                            doit(checkDate)
                            aWorkSheet.Cells(intRow, intCol) = "Holiday"
                            aWorkSheet.Cells(intRow, intCol).Font.Bold = True
                            aWorkSheet.Cells(intRow, intCol).Font.Underline = True
                            aWorkSheet.Cells(intRow, intCol).Font.Size = 10
                            aWorkSheet.Cells(intRow, intCol).HorizontalAlignment = 3
                            strCell1 = cellz & CStr(intRow + 3)
                            strCell2 = cellz & CStr(intRow + 10)
                            aWorkSheet.Range(strCell1, strCell2).Interior.Color = RGB(192, 192, 192)
                            Exit Do
                        Else
                            cellz = ""
                        End If
                        x = x + 1
                    Loop
                    x = 0
                    checkDate = checkDate.AddDays(1)
                Loop
 
                aWorkSheet.Cells(5, 2) = calTimesheet.SelectionStart.Date
                aWorkSheet.Cells(43, 11) = Date.Today.Now.Date
            Case 2 'Salary
                If Switch = False Then
                    aWorkSheet.Cells(35, 1) = txtEmpNum.Text
                    aWorkSheet.Cells(37, 3) = txtName.Text
                    aWorkSheet.Cells(7, 2) = "X"
                    aWorkSheet.Cells.Range("E7", "H7").Value = "X"
                    aWorkSheet.Cells.Range("E17", "I17").Value = "X"
                End If
 
                aWorkSheet.Cells(5, 2) = calTimesheet.SelectionStart
                aWorkSheet.Cells(37, 10) = Date.Today.Now.Date
            Case 3 'Standard
                If Switch = False Then
                    aWorkSheet.Cells(40, 1) = txtEmpNum.Text
                    aWorkSheet.Cells(40, 7) = txtName.Text
                End If
 
                aWorkSheet.Cells(5, 2) = calTimesheet.SelectionStart.AddDays(2)
        End Select
 
        filename = "C:\Documents and Settings\" & username & "\Timesheet\" & strTimeSheet
        aExcel.ActiveWorkbook.SaveAs(filename)
        aExcel.ActiveWorkbook.Close()
 
        Call Settings()
        System.Diagnostics.Process.Start("Excel.EXE", filename)
        End
    End Sub
[+][-]12.31.2007 at 08:27AM PST, ID: 20555847

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.02.2008 at 08:24AM PST, ID: 20565431

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.02.2008 at 11:58AM PST, ID: 20567277

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET, Visual Basic Programming, Development Software
Tags: Microsoft, Office, 2003, VB.Net 2003, Iexplore, System.InvalidCastException: QueryInterface for interface Microsoft.Office.Interop.Excel._Application failed
Sign Up Now!
Solution Provided By: graye
Participating Experts: 1
Solution Grade: A
 
 
[+][-]01.07.2008 at 09:17AM PST, ID: 20601031

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628