Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664

    Why won't this program compile?

    In the two files attached is a zip file that contains the database with a form that exports MS Access tables to MS Excel.

    The code is show in a Snagit photograph that is the second file attached. This code fails on the first line.

    Dim x1 As Excel.App...



    I am not sure why. It could be because I have not installed

    Microsoft Excel 14.0 Object Library

    ?

    I am just curious as to why it fails on the first line.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Yes, you're using early binding, which requires the Excel reference be checked in Tools/References.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay that is what I will do. By the way, what version of Microsoft Excel 14 Object Library should I be using? I chose 14? I have MS Excel 2010 and MS Access 2010.

    Thanks in advance.

    Respectfully,

    Lou Reed

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You need to choose the one on the computer. The problem arises if/when you distribute the application and other users have different versions of Excel installed. Most of us use late binding to avoid that:

    https://support.microsoft.com/en-us/...-in-automation
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, how do I modify to avoid late binding.

    I went to Tools --> References and

    the Microsoft Excel 14 Object Library was already checked.

    See attached files.

    So I am unsure how to avoid this and I clearly need to know about late binding.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    One of us is blind. The Excel library is not one of those checked in your picture.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I was the one who could not see. I am the one. However, when I did check the MS Excel 14 Object Library it did compile that line, but failed on a latter line see PDF file). I think the syntax is correct. What is wrong?

    Any help appreciated. Thank in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  8. #8
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I fixed some error in my VBA code. I had two end sub lines. I only have one now, but I still
    cannot get the line

    Set db = CurrentDb

    to compile. I am guessing that I must add another library since I see no syntax error.

    Any help appreciated. Thank in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You've declared the variable incorrectly, should be:

    Dim db As DAO.Database
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Yes, I caught that error thanks very much for pointing it out.

    I have uploaded two zip files. One is an Access application and the other is an Excel application.

    I am trying to import the table, Table1 into the Excel spreadsheet TestBook.xlxs from Access.

    it is failing with an index out range error. I am unsure as to why.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    This line refers to a sheet that doesn't exist:

    Set ws = xl.ActiveWorkbook.Sheets("newdata")

    The next error you hit should be obvious.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    And once you fix that, it "works", but doesn't really; see if you recognize why.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Wait a second now. i named the Excel sheet "TestBook" and yes I gave it the correct path:


    V:\Users\Newport_j\Desktop\TestBook.xlsx

    It should work with that, shouldn't it.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The sheet, not the file. Did you notice the line of code I posted? The sheet is named "Sheet1".
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #15
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, I guess i never really thought that each sheet had a name. It does: "sheet1". That is a pretty mundane name.

    Is that really the name of the sheet - sheet 1?

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Compile error next without for
    By cc.caroline15 in forum Programming
    Replies: 3
    Last Post: 03-08-2015, 01:33 PM
  2. Getting a compile error
    By alansidman in forum Programming
    Replies: 14
    Last Post: 02-11-2012, 01:12 PM
  3. Why do I get a compile error?
    By shabbaranks in forum Programming
    Replies: 24
    Last Post: 10-18-2011, 07:51 PM
  4. Program a 30-day trial into my Access Program?
    By genghiscomm in forum Programming
    Replies: 1
    Last Post: 05-26-2011, 02:14 PM
  5. new compile error!
    By darklite in forum Access
    Replies: 6
    Last Post: 09-02-2010, 05:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums