Writing to Excel 2007 From Access (1 Viewer)

winshent

Registered User.
Local time
Today, 20:09
Joined
Mar 3, 2008
Messages
162
For some reason this code fails when i try and write past row 65536 in excel. The code creates an excel 12 workbook, and when i open it, it has over 1 million rows in it..

Code:
Sub TestWriteExcel()
  On Error GoTo PROC_ERR
 
  Dim app As Excel.Application, wb As Workbook, ws As Worksheet
 
  Set app = New Excel.Application
 
  Set wb = app.Workbooks.Add
  wb.SaveAs "U:\Data\CEF\test", xlExcel12
  DoEvents
 
  Set ws = wb.Worksheets.Add
  ws.Name = "test"
 
  ws.Cells(65536, 1).Value = 1
  ws.Cells(65537, 1).Value = 2
  wb.Save
PROC_EXIT:
  On Error Resume Next
  wb.Close
  app.Quit
  Set ws = Nothing
  Set wb = Nothing
  Set app = Nothing
  Exit Sub
 
PROC_ERR:
  Debug.Print Err.Number & vbCrLf & Err.Description
  Resume PROC_EXIT
 
End Sub

I even tried similar code within excel and that works fine. I have excel12.0 object library referenced..

Anyone know how to fix this?
 

boblarson

Smeghead
Local time
Today, 12:09
Joined
Jan 12, 2001
Messages
32,059
Wishent -

Are you doing this from an Access 2007 .ACCDB file?
 

boblarson

Smeghead
Local time
Today, 12:09
Joined
Jan 12, 2001
Messages
32,059
Then change this:

wb.SaveAs "U:\Data\CEF\test", xlExcel12

to this:

wb.SaveAs "U:\Data\CEF\test.xlsx"
 

winshent

Registered User.
Local time
Today, 20:09
Joined
Mar 3, 2008
Messages
162
Then change this:

wb.SaveAs "U:\Data\CEF\test", xlExcel12

to this:

wb.SaveAs "U:\Data\CEF\test.xlsx"

have tried that before.. still get the same error:

1004
Application-defined or object-defined error
 

boblarson

Smeghead
Local time
Today, 12:09
Joined
Jan 12, 2001
Messages
32,059
Do you have Excel 12 selected in your references? Also, you should change this

Dim app As Excel.Application, wb As Workbook, ws As Worksheet

to this

Dim app As Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
 

winshent

Registered User.
Local time
Today, 20:09
Joined
Mar 3, 2008
Messages
162
Do you have Excel 12 selected in your references?

yes

Also, you should change this

Dim app As Excel.Application, wb As Workbook, ws As Worksheet

to this

Dim app As Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet

Not sure why that would make any difference? I prefer to declare on one line to condense my code..

I did try it btw and it didnt make any difference..
 

boblarson

Smeghead
Local time
Today, 12:09
Joined
Jan 12, 2001
Messages
32,059
yes



Not sure why that would make any difference? I prefer to declare on one line to condense my code..
Wasn't that, it was to have Excel. part in there.

Well, not sure as I've had no problems in saving to an Excel 2007 format before from Access 2007. I'll have to take a look when I get home to see what I can see. In the meantime, can you post your database? If you need to scramble the data, I have a tool that can do that for you.
 

winshent

Registered User.
Local time
Today, 20:09
Joined
Mar 3, 2008
Messages
162
I'll have to try and post it up tomorrow..

But can you get something what i am trying to do to work?
 

boblarson

Smeghead
Local time
Today, 12:09
Joined
Jan 12, 2001
Messages
32,059
But can you get something what i am trying to do to work?
I think so, but I need to actually play with it. And see the attached file to use to scramble any text data like names, addresses, etc.
 

Attachments

  • DataScramble.mdb
    152 KB · Views: 124

winshent

Registered User.
Local time
Today, 20:09
Joined
Mar 3, 2008
Messages
162
Hi Bob

Thanks for your help on this..

Did you try to get the script running yourself?

I cant ftp a file to any external site while I am at work. I might be able to upload it over the weekend..

Thanks

Vincent
 

Users who are viewing this thread

Top Bottom