Solved

exporting into a file with header in access

Posted on 2015-02-24
3
89 Views
Last Modified: 2016-02-12
How do you export from access into a excel file with the excel file with a header already formatted.


I want to be able to export the data starting from row 15 in the excel file and how do you call the same file and still be able to export data again and again
0
Comment
Question by:Jass Saini
3 Comments
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 40628865
To do this, you need to make Access start an instance of Excel, and use Excel vba to write to the worksheet.

Typically I'd use code something like

Dim xl As Object
Dim xlw As Object
Dim xls As Object

Set xl = CreateObject("Excel.Application")
xl.DisplayAlerts = False
xl.Visible = False

Set xlw = xl.Workbooks.Add
xlw.SaveAs sWB, FileFormat:=56 ''Fileformat 56 is the excel 97-2003 file format for xls files

Set xls = xlw.Worksheets("Sheet1")
xls.Name = "Record Sheet"
xls.SELECT
xls.Activate

From there you need to manage what cell or cells you are using and what you want to happen.


Kelvin
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 40628900
try this codes, replace objects as appropriate with your actual object names.

Sub exp2XL()
Dim rs As DAO.Recordset
Dim xlObj As Object
Dim Sheet As Object

Set rs = CurrentDb.OpenRecordset("select * from queryName")

If rs.EOF Then Exit Sub

    Set xlObj = CreateObject("Excel.Application")
    xlObj.Workbooks.open "c:\folder\excelfile.xlsx"
      
      Set Sheet = xlObj.activeworkbook.Sheets("sheet1")
      
       Sheet.Range("A15").CopyFromRecordset rs  'copy the data
      
    Set Sheet = Nothing
    xlObj.Quit
    Set xlObj = Nothing
      
end sub
0
 

Author Closing Comment

by:Jass Saini
ID: 40642735
Thanks
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question