Results 1 to 16 of 16

Thread: [RESOLVED] Need help exporting data to excel 2007

  1. #1

    Thread Starter
    New Member supeazn's Avatar
    Join Date
    Apr 2010
    Location
    Oakdale, MN
    Posts
    15

    Resolved [RESOLVED] Need help exporting data to excel 2007

    Basically I'm taking data from an Access 2000 database and dumping it in Excel. Although this concept works for Excel 2003, but not Excel 2007. I'm using Vb6 for this process.

    Sample Code:

    'The dialog box that asks the user where to save the document or object
    With CommonDialog1
    .InitDir = customer_root
    .DefaultExt = ".xlsx"
    .Filter = "Excel Workbook (*.xlsx)|*.xlsx"
    .ShowSave
    .CancelError = True 'If the user clicks cancel then the program exits
    the sub
    End With

    ExcelName = "Excel 8.0;DATABASE=" 'I've tried setting this to 12.0 but no luck.

    sql = "SELECT " & NewData & " INTO [" Excel 8.0;DATABASE=C:\Test.xlsx].[12_2_2009]] " & _
    " FROM NewTable " & _
    " WHERE (Line < 900) OR (Line >= 900 AND Action01 = 1) ORDER BY EndStep"

    Debug.Print sql

    objDB.Execute sql

  2. #2

    Thread Starter
    New Member supeazn's Avatar
    Join Date
    Apr 2010
    Location
    Oakdale, MN
    Posts
    15

    Re: Need help exporting data to excel 2007

    There is an extra bracket in the sql statement because i edited please ignore cause its not in the original code.

  3. #3

    Thread Starter
    New Member supeazn's Avatar
    Join Date
    Apr 2010
    Location
    Oakdale, MN
    Posts
    15

    Re: Need help exporting data to excel 2007

    Running the above code i get this error

    Error Code: 3027
    Cannot update. Database or object is read-only.

    it's because of the variable "ExcelName". Setting it to 12.0 gave another error about not being able to find the installable ISAM. Already googled it and went through all the scenarios provided by other experts like install the latest version of Jet and MDAC. Do you guys think vb6 understands the 4 character extension or Excel 2007 ?

  4. #4
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Need help exporting data to excel 2007

    Why not dump it to Excel 2003 and just open it with 2007?
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  5. #5

    Thread Starter
    New Member supeazn's Avatar
    Join Date
    Apr 2010
    Location
    Oakdale, MN
    Posts
    15

    Re: Need help exporting data to excel 2007

    Because I need to dump over 70,000 rows of data for a report. 2003 can only handle up to 65,000 and 2007 and handle over 1,000,000 (with some registry mod). It's for work.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Need help exporting data to excel 2007

    Welcome to VBForums

    You haven't shown how you set up the connection, but I suspect you are using JET, which does not know about the recent file types. What you should be using instead is ACE, which you can get via the link in my signature (another link shows examples of connection strings).

    Alternatively, if Excel will be installed on the computer your code is running on, you can use Automation to work with whatever version of Excel is installed. See my tutorial (link in my signature) for details.

  7. #7

    Thread Starter
    New Member supeazn's Avatar
    Join Date
    Apr 2010
    Location
    Oakdale, MN
    Posts
    15

    Re: Need help exporting data to excel 2007

    Thanks for welcoming me to the forums. I'll check out the links.

  8. #8

    Thread Starter
    New Member supeazn's Avatar
    Join Date
    Apr 2010
    Location
    Oakdale, MN
    Posts
    15

    Re: Need help exporting data to excel 2007

    Thanks si for the help. I was able to write the data to excel 2007, but now the other dilemma is it gives me an error when i try to open the file. Err msg: Excel cannot open " & insert file name & " the file format or file extension is not valid.

    vb Code:
    1. 'The dialog box that asks the user where to save the document or object
    2.         With CommonDialog1
    3.             .InitDir = customer_root
    4.             .DefaultExt = ".xlsx"
    5.             .Filter = "Excel Workbook (*.xlsx)|*.xlsx"
    6.             .ShowSave
    7.             .CancelError = True 'If the user clicks cancel then the program exits the sub
    8.         End With
    9.        
    10.             sql = "SELECT " & NewData & " INTO [" & Excel 12.0;DATABASE & strExcelFile & "].[" & wkshCallDetail & "] " & _
    11.             " FROM NewTable " & _
    12.             " WHERE (Line < 900) OR (Line >= 900 AND Action01 = 1) ORDER BY EndStep"
    13.             cnnaccess.execute sql

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Need help exporting data to excel 2007

    You've got a significant typo there, I think it should be like this:
    Code:
                sql = "SELECT " & NewData & " INTO [Excel 12.0;DATABASE=" & strExcelFile & "].[" & wkshCallDetail & "] " & _

  10. #10

    Thread Starter
    New Member supeazn's Avatar
    Join Date
    Apr 2010
    Location
    Oakdale, MN
    Posts
    15

    Re: Need help exporting data to excel 2007

    oh yea that's how it looks my bad.

    This is how it looks in debug mode



    SELECT Onion,CallCounter AS [ORCA Call ID],NetworkConnect as [Network Connect],Start,EvaluatedResult,EndStep,Answer,Done,ANI,TestCase AS [Test Case],Call_Time,Data01,Time01,Data04_01,Time04_01,Data05_01,Time05_01,Audio INTO [Excel 12.0;DATABASE=C:\!Drill\_H&RBlock_CallDetailReport_20091202_TOOLaaa.xlsx].[12_2_2009] FROM NewTable WHERE (Line < 900) OR (Line >= 900 AND Action01 = 1) ORDER BY EndStep


  11. #11

    Thread Starter
    New Member supeazn's Avatar
    Join Date
    Apr 2010
    Location
    Oakdale, MN
    Posts
    15

    Re: Need help exporting data to excel 2007

    It seems as if excel 2007 won't let you the above code, so i got it work with the copyfromrecordset.

  12. #12
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Need help exporting data to excel 2007

    Quote Originally Posted by supeazn View Post
    Because I need to dump over 70,000 rows of data for a report. 2003 can only handle up to 65,000 and 2007 and handle over 1,000,000 (with some registry mod). It's for work.
    I will suggest the same thing to you what I suggested this guy and I will leave the decision to you...

    http://www.vbforums.com/showpost.php...3&postcount=13
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  13. #13

    Thread Starter
    New Member supeazn's Avatar
    Join Date
    Apr 2010
    Location
    Oakdale, MN
    Posts
    15

    Re: Need help exporting data to excel 2007

    Thanks for the suggestion. Because we are in the mist of converting to Office 2007 and dumping 2003 (i know it sucks). I got it to work like i said ^.

  14. #14

    Thread Starter
    New Member supeazn's Avatar
    Join Date
    Apr 2010
    Location
    Oakdale, MN
    Posts
    15

    Re: Need help exporting data to excel 2007

    i got this to work. Please close !

  15. #15
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Need help exporting data to excel 2007

    If you consider your question to be resolved then pull down the Thread Tools menu and click the Mark Thread Resolved menu item. That will let everyone know that you have your answer.

    Thank you.

  16. #16

    Thread Starter
    New Member supeazn's Avatar
    Join Date
    Apr 2010
    Location
    Oakdale, MN
    Posts
    15

    Re: [RESOLVED] Need help exporting data to excel 2007

    Kool thanks !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width