VB write to EXCEL  ERROR

Posted on 2012-09-17
Last Modified: 2012-09-22
I have some problem. It all works on my 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

What could I have missed?

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

    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()
        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

        End Try

    End Sub

Open in new window

Question by:kavvis
    LVL 33

    Assisted Solution

    Where in the code do you get the problem?

    Accepted Solution

    I should be at line 24

    "   Private Sub Write_To_Excel()
    Only place I have the try catch..
    LVL 33

    Expert Comment

    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


    Author Closing Comment

    Mybad... hade wrong Framework... thank you that you took your time..

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Suggested Solutions

    Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
    Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
    The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
    This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now