transfer to a particular sheet in workbook

Joe C

Well-known Member
Joined
Oct 17, 2002
Messages
841
How would I adjust this command to transfer to a particular sheet of a work book. Is it possible.

DoCmd.TransferSpreadsheet acExport,
acSpreadsheetTypeExcel97, "qtable1", savename, True
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
not sure I understand.

Transfer an existing spreadsheet?
To where?

If you're trying to move an existing sheet from onw WB to another (from Access), you'll need to expose the Excel Object model in your Access VBA code and do it basically like you would from Excel.
 
Upvote 0
Hi,

This is going to be tricky. The
'DoCmd.TransferSpreadsheet acExport,
acSpreadsheetTypeExcel8, "YourQuery/Table

automatically goes to the first sheet, as well as
DoCmd.OutputTo acReport, "MyReport", acFormatXLS

The only option I can think of, is to leave your first page blank, and cut and paste it to another sheet from Access.

Code:
Sub export() 

'name spreadsheet for object reference 
Dim ExcelSheet As Object 

'name string vars for dir and spreadsheet file name 
Dim savename As String 

'Add reference to Excel library 
Call XLLibrary 

'get path info 
savename = inputbox("Where would you like to save?") 

'transfer qryXL to file 'savename', closes file 
'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "YourQuery/Table", Savename, True 

'opens new file 
Workbooks.Open Filename:=savename 

'set object 'savename'(excel spreadsheet) for action 
Set ExcelSheet = Workbooks.Application.ActiveWorkbook 

'all excel VBA
With ExcelSheet 
    .Application.Visible = True
    .Sheets(1).Cells.Copy
    .Sheets(2).Paste
    .Save 
    .Quit 
End With 

End Sub 
_________________________________________
Sub XLLibrary() 

'Add reference to Excel library 

On Error Resume Next 
Application.References.AddFromGuid "{00020813-0000-0000-C000-000000000046}", 2, 3 

End Sub

Of course, if you could leave the first page blank, you probably wouldn't need to export to another one, so my answer may be of little help.

You could try importing into Excel instead of exporting, perhaps. If this is a possibility, let us know.

edit:
This:
'DoCmd.TransferSpreadsheet acExport,
acSpreadsheetTypeExcel8, "YourQuery/Table
can create a new spreadsheet. You could then modify the above code to copy the page from this new spreadsheet, and paste it into your existing one, and then delete the tesmp worksheet.

HTH,
 
Upvote 0

Forum statistics

Threads
1,221,513
Messages
6,160,244
Members
451,632
Latest member
purpleflower26

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top