• Excel from Access VBA

    Author
    Topic
    #461644

    I have the following simple code and have no idea why it is throwing an error:

    Dim appExcel As Excel.Application
    Dim wkb As Excel.Workbook
    Dim wst As Excel.Worksheet
    Dim intCount As Integer
    Dim strSql As String
    Dim strSql2 As String
    Dim strSection As String
    Dim intSequence As Integer

    strSql = …
    strSql2 = “…

    Set appExcel = CreateObject(“Excel.Application”)

    Set rstStudents = CurrentDb.OpenRecordset(strSql, dbOpenDynaset)
    Set rstClasses = CurrentDb.OpenRecordset(strSql2, dbOpenDynaset)

    Set wkb = appExcel.Workbooks.Add()
    Set wst = wkb.Sheets(1)
    wst.Activate
    appExcel.Visible = True

    When it gets to workbooks.add I get “Method add of object workbooks failed”

    Any ideas?
    Thanks

    Viewing 0 reply threads
    Author
    Replies
    • #1172028

      Does it make a difference if you omit the brackets?

      Set wkb = appExcel.Workbooks.Add

      • #1172100

        Does it make a difference if you omit the brackets?

        Set wkb = appExcel.Workbooks.Add

        No, I had tried that first.
        Thanks

        • #1172109

          Is there other code between the line

          Set appExcel = CreateObject(“Excel.Application”)

          and

          Set wkb = appExcel.Workbooks.Add()

          that you haven’t posted?

          • #1172117

            Is there other code between the line

            Set appExcel = CreateObject(“Excel.Application”)

            and

            Set wkb = appExcel.Workbooks.Add()

            that you haven’t posted?

            no- just the rest of strsql that is just a string that I checked already works.

            • #1172120

              The code itself is correct, so there appears to be a problem with the Excel object. Does the problem persist after restarting your PC?

            • #1172187

              The code itself is correct, so there appears to be a problem with the Excel object. Does the problem persist after restarting your PC?

              yes. I think it might be because I have both 2007 and the beta of 2010 installed on my computer. I am going to try this on a simpler instal and see what happens.
              Thanks

            • #1172190

              yes. I think it might be because I have both 2007 and the beta of 2010 installed on my computer. I am going to try this on a simpler instal and see what happens.
              Thanks

              Is Office 2010 on its’ way?

            • #1172192

              Is Office 2010 on its’ way?

              See Microsoft Office 2010 on Wikipedia.

            • #1172194

              See Microsoft Office 2010 on Wikipedia.

              Thanks Hans.

            • #1172203

              Is Office 2010 on its’ way?

              I ave been using the technical preview (beta). Not any major changes in the front end of Access, did not yet get a chance to sue the new macro editor which look interesting. Also they redid the build button in creating Dfunctions etc. However, Outlook 2010 is great.

            • #1172232

              Any chance graphing will work again in Access 2010?

            • #1172299

              This is not the place to discuss Office 2010 Beta. Moreover, this topic is about starting Excel from Access, please don’t hijack it.

            • #1172337

              This is not the place to discuss Office 2010 Beta. Moreover, this topic is about starting Excel from Access, please don’t hijack it.

              Sorry you are correct

            • #1172202

              The code itself is correct, so there appears to be a problem with the Excel object. Does the problem persist after restarting your PC?

              due to some other issues also I uninstalled 2010 and 2007 then reinstalled only 2007, but I still have the issue. Very weird and annoying.Still have not had a chance to try it somewhere else

    Viewing 0 reply threads
    Reply To: Excel from Access VBA

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: