[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

VB write to EXCEL ERROR

Hi!
I have some problem. It all works on my dev.computer but when I test on new computer I get errors...

I have Excel 2007 insalled whit the same version on both computers.
It works perfect on my dev.computer.

What could I have missed?


 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Init_excel()

        Write_To_Excel()
    End Sub

    ' Initera Excel och korrekt excel fil
    Private Sub Init_excel()

        On Error Resume Next
        objApp = GetObject(, "Excel.Application")
        If Err.Number <> 0 Then
            objApp = CreateObject("Excel.Application")
        End If
        objBook = objApp.Workbooks.Open("C:\b\Report.xls")

    End Sub


 Private objApp As Object, objBook As Object

    ' Find last row then write
    Private Sub Write_To_Excel()
        Try
		
        With objBook.sheets("Blad1")

            Dim sistaraden As Integer

            LastROW = objBook.sheets("Blad1").Range("a1").End(-4121).Row
            LastROW = LastROW

       
            ' data
            .cells(LastROW + 1, 1).Value = '99'
            .cells(LastROW + 1, 2).Value = '909'
            .cells(LastROW + 1, 3).Value = "gfgf"
            .cells(LastROW + 1, 4).Value = FLroduurs
            .cells(LastROW + 1, 5).Value = FonMies
            .cells(LastROW + 1, 6).Value = FLurs
            .cells(LastROW + 1, 7).Value = Furs
            .cells(LastROW + 1, 8).Value = X_Alates
            .cells(LastROW + 1, 9).Value = aties
            .cells(LastROW + 1, 10).Value = ister
            .cells(LastROW + 1, 11).Value = F_cy

       
            End With

        Catch ex As Exception
            MsgBox(ex.ToString)

        End Try

        objBook.Save()
    End Sub

Open in new window

picture.png
0
kavvis
Asked:
kavvis
  • 2
  • 2
2 Solutions
 
NorieCommented:
Where in the code do you get the problem?
0
 
kavvisAuthor Commented:
I should be at line 24

"   Private Sub Write_To_Excel()
        Try
"
Only place I have the try catch..
0
 
NorieCommented:
Are you sure the path and filename are correct?

When I tested the code I accidentally put the file in the wrong folder and received the message you did.

I only found out after I stepped through the code using F11.

By the way, it should be double quotes around values, not single quotes.
     .cells(LastRow + 1, 1).Value = "99"
     .cells(LastRow + 1, 2).Value = "909"

Open in new window

0
 
kavvisAuthor Commented:
Mybad... hade wrong Framework... thank you that you took your time..
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now