Question .exe deployment error Excel

Jacques Grobler

New member
Joined
Aug 8, 2011
Messages
2
Programming Experience
1-3
Hi guys,

I'm from a VBA background and a little bit new to VB.net. I have recently written a piece of code to capture the time spent on the project. For now it is VERY basic and need to sort out a couple of small problems before I carry on.

The problem is that, when I am directly in VS, my program works well, but when I build it as a standalone .exe, and run it, I get an error (as attached).

Below is my code as I have it running, what is wrong?

Form:
VB.NET:
Imports Excel = Microsoft.Office.Interop.Excel

Public Class frmTimeLogger

    Dim newPoint As New System.Drawing.Point()
    Dim a As Integer
    Dim b As Integer

    Private Sub frmTimeLogger_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
        a = Control.MousePosition.X - Me.Location.X
        b = Control.MousePosition.Y - Me.Location.Y
    End Sub

    Private Sub frmTimeLogger_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
        If e.Button = MouseButtons.Left Then
            newPoint = Control.MousePosition
            newPoint.X = newPoint.X - (a)
            newPoint.Y = newPoint.Y - (b)
            Me.Location = newPoint
        End If
    End Sub

    Private Sub frmTimeLogger_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.TopMost = True
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
    End Sub

    Private Sub lbl_Close_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbl_Close.Click
        Me.Close()
    End Sub

    Private Sub releaseObject(ByVal obj As Object)
        Try
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
            obj = Nothing
        Catch ex As Exception
            obj = Nothing
        Finally
            GC.Collect()
        End Try
    End Sub

    Private Sub lbl_Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbl_Submit.Click
        Dim xlApp As Excel.Application
        Dim xlWorkBook As Excel.Workbook
        Dim xlWorkSheet As Excel.Worksheet
        Dim LastRow As Long

        xlApp = New Excel.Application

        xlWorkBook = xlApp.Workbooks.Open("C:\Dropbox\ACTOM APC\TimeTracking\TimeLogger.xlsx")
        xlWorkSheet = xlWorkBook.Worksheets("Sheet1")

        With xlApp
            .Range("B2").Select()
            .Selection.End(xlDown).Select()
            LastRow = .ActiveCell.Row()
        End With

        xlWorkSheet.Cells(LastRow + 1, 2) = Val(Me.txtProject.Text)
        xlWorkSheet.Cells(LastRow + 1, 3) = Now()
        xlWorkBook.Close()
        'xlApp.DisplayAlerts = False
        xlApp.Quit()

        releaseObject(xlApp)
        releaseObject(xlWorkBook)
        releaseObject(xlWorkSheet)
    End Sub

End Class

Constants module:
VB.NET:
Module Constants
    Public Const xlDown = -4121
End Module

I will greatly appreciate any help

Jacques
 

Attachments

  • untitled.bmp
    225.7 KB · Views: 24
Back
Top