Results 1 to 2 of 2
  1. #1
    saikat_datta is offline Novice
    Windows 10 Access 2007
    Join Date
    Dec 2015
    Posts
    3

    Expoting Data to Excel with Formatting.

    Hi Sir,



    I have a code in a command button to export data from access to excel. it looks like........

    Private Sub Command47_Click()
    'Export function
    'EXPORTS TABLE IN ACCESS DATABASE TO EXCEL
    'REFERENCE TO DAO IS REQUIRED


    Dim strExcelFile As String
    Dim strWorksheet As String
    Dim strDB As String
    Dim strQuery As String
    Dim objDB As Database


    'Change Based on your needs, or use
    'as parameters to the sub
    strExcelFile = "F:\Project\Somenath_Report1.xls"
    strWorksheet = "WorkSheet1"
    strDB = "F:\Project\Software Hardware1"
    strQuery = "Somenath"


    Set objDB = OpenDatabase(strDB)


    'If excel file already exists, you can delete it here
    If Dir(strExcelFile) <> "" Then Kill strExcelFile


    objDB.Execute _
    "SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & _
    "].[" & strWorksheet & "] FROM " & "[" & strQuery & "]"
    objDB.Close
    Set objDB = Nothing

    End Sub


    It works Fine. But i want my Excel file to be a bit formatted. Headers in Bold and as per the size of field and if possible apply cell border. Is it possible? If yes, can anyone provide me with codes?

    I am new in Access.
    Regards
    Saikat

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,820
    Use Excel macro builder to get the basic code for cell formatting. Then adapt for Access VBA.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 07-01-2014, 10:10 AM
  2. Export Data to Excel Pivot Table Loss of Formatting
    By Damian in forum Import/Export Data
    Replies: 1
    Last Post: 05-17-2013, 07:56 PM
  3. Excel export formatting
    By tariq nawaz in forum Import/Export Data
    Replies: 0
    Last Post: 09-24-2012, 05:30 AM
  4. Keeping Column Captions when exporting expoting pivot table
    By UofAHogs in forum Import/Export Data
    Replies: 1
    Last Post: 06-04-2012, 12:46 AM
  5. VBA Excel Formatting: Need new eyes!!
    By Lorlai in forum Programming
    Replies: 3
    Last Post: 06-09-2011, 10:22 AM

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