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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exporting to Excel

Status
Not open for further replies.

Moostang

ISP
Jan 11, 2003
5
US
I'm trying to export a table to excel, that part works fine, but is there a variable or anything else that I can add to the code or macro to export it to a specific sheet within an exsisting excel workbook?
 
p.s. I'm exporting From ACCESS 2000. Sorry about leaving that key info out.
 
What EXACTLY are you asking?
If you are trying to activate a certain sheet of a workbook try this...
Code:
  Dim xlBook As Excel.Workbook
  Dim xlSheet As Excel.Worksheet
  
  Set xlBook = Excel.ActiveWorkbook
  Set xlSheet = xlBook.Sheets.Item("sheet2")
  xlSheet.Activate

if you are in another app... (Word, Acces...)
Code:
  Dim xlApp As Excel.Application
  Dim xlBook As Excel.Workbook
  Dim xlSheet As Excel.Worksheet
  
  Set xlApp = Excel.Application
  xlApp.Visible = True
  Set xlBook = Excel.Workbooks.Add
  Set xlSheet = xlBook.Sheets.Item("sheet2")
  xlSheet.Activate

and you need to set a reference to Microsoft Excel X.X Objects Library
with Tools>References... inside the VBA editor

Good Luck Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
I have a query in Access that pulls information from a remote database. I then put that data into a local table and export that table to excel. I have a workbook that has a spreadsheet setup to get it's information from the information exported table. I want to be able to export the data from Access to the exsisting workbook, just a different sheet. Below is the code I was using to export the table.

Public Sub Export()
DoCmd.OutputTo acOutputTable, "Canceled Table", acFormatXLS, "M:\Updated Cancel Reports\Canceled.xls", False

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top