Exporting to Excel, naming the worksheet/tab

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • itsNOTaTOOMAH
    New Member
    • Nov 2010
    • 1

    #1

    Exporting to Excel, naming the worksheet/tab

    I have an Access query and/or table that I'm exporting into an Excel spreadsheet using the TransferSpreads heet action in VBA:

    DoCmd.TransferS preadsheet acExport, acSpreadsheetTy peExcel97, "QueryName" , "C:\ExportedFil e.xls"

    Using this particular code will export my data to a worksheet named "QueryName" , but is there any way to export the query/table to Excel but to a tab with a different name - without renaming the query/table? For example, if in my database, I have the table "TableX", how can I export this to an Excel file, where the data from TableX is on a worksheet named "Worksheet2010" ?


    I hope this was clear, and appreciate any and all help.



    Thanks!
  • Mariostg
    Contributor
    • Sep 2010
    • 332

    #2
    This should get you started. Basically, you name your sheet after you create you XL object:
    Code:
    Dim XlApp As New Excel.Application
    Dim XlBook As Excel.Workbook
    Dim Xlsheet As Excel.Worksheet
    Set XlBook = XlApp.Workbooks.Add
    Set Xlsheet = XlBook.Worksheets(2)
    Xlsheet.Name = "WhatEverYouWant"  'Set this name to sheet2

    Comment

    Working...