Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create excel sheet 2

Status
Not open for further replies.

LARiot

Programmer
Feb 7, 2007
232
Hi,

Does anyone have a simple reference or code sample to write data to an Excel sheet from Access VBA?

Basically to create a new excel file, write to it's cells then close. The threads I found here did strange stuff and didn't work.

Thanks.

-Neema
 
'Cause it wouldn't work. A lot of literals and the data doesn't fit into a regular recordset format. That is, the fields do not go horizontally across the top. Ten rows constitute one record.

-Neema
 
So do you want to use automation?

Code:
Dim xl As Excel.Application
Dim xwb As Excel.Workbook
Dim xws As Excel.Worksheet

Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset("tbl")
Set xl = CreateObject("Excel.Application")
Set xwb = xl.Workbooks.Add

Set xws = xwb.Worksheets.Add

xws.Range("A1") = rs.Fields(1)

xl.Visible = True
xl.UserControl = True
 
Thanks Remou. Do I have to create any references? It says User-Defined type no defined off the first line.


-Neema
 
Yes, you will need a reference to the Microsoft Excel x.x Object Library.
 
OK so it was the Microsoft Excel 11.0 Object Library.

What's automation? Sounds like an 80's dance song.

-Neema
 
Hey we could start an 80s cover band. What do you think Remou? You in?

-Neema
 
I am having another slight problem.

When I write:
Code:
xws.Range(sLetter & sNumber) = "94000.1170"

It drops the zero at the far right. It's treating it as a number instead of a string expression. It's in quotes and I tried cstr("94000.1170") I tried putting it into a string... any ideas?

Thanks.

-Neema
 
You need a single quote:

Code:
xws.Range(sLetter & sNumber) = "[COLOR=red yellow]'[/color]94000.1170"
 
Wow Remou, is there anything you can't do?

-Neema
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top