Copying from Access. Pasting to Excel

shlobodon

New Member
Joined
Oct 15, 2015
Messages
44
Hello,

I am having difficulty transferring data from Access to Excel using VBA. Originally, I wanted to use the DoCmd.TransferSpreadsheet acExport method. However, I was having difficulties exporting to a specific Excel file, sheet, and cell. This is what my coding looked like

mydb.DoCmd.TransferSpreadsheet acExport, 8, "NB Savings Final", "K:\nataccts\1Reports\1 - Strategic Partners\Customer\Cost Savings\2016\Customer_Cost Savings_Jan" & YTDMonth & "2016.xlsx", True, "NB Savings!B4:N2467"

I decided to give up on this since I was having problems and copying a table to my clipboard would have worked just as well. However, I am having issues with this, too. I have written a similar code that moves info between 2 excel files in a previous project. I have provided this coding.

Windows("CSA for Requisition Review Program_Master.xls").Activate
Sheets("DCS Form").Activate
Rows("5").Select
Selection.Copy
Windows("Req Review Program CSA YTD File v3.xlsb").Activate
Sheets("Sheet1").Activate
Rows("1").Select
ActiveSheet.Paste
Windows("CSA for Requisition Review Program_Master.xls").Activate
Sheets("DCS Form").Activate

This is what I am looking to do between Access and Excel. I am having difficulties switching to Access then copying the table data. I have gotten this far...

mydb.DoCmd.OpenTable "EB Savings Final", acViewNormal, acEdit
mydb.DoCmd.SelectObject acTable, "EB Savings Final"


mydb.RunCommand acCmdSelectAllRecords


mydb.RunCommand acCmdCopy
mydb.DoCmd.Close acTable, "Changeboard query", acSaveNo
Windows("Customer_Cost Savings_Jan" & YTDMonth & "2016.xlsx").Activate
Sheets("EB Savings").Activate
Range("B4").Paste


I am hoping that someone would be able to provide me with the correct coding for either the DoCmd.TransferSpreadsheet acExport or clipboard method. Thanks in advance.

-Rob
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Tips:
- always give details on the failure - otherwise, no clues makes it difficult if not impossible to help on the first try.
- I've never seen anything like your "mydb" preface before Access objects like DoCmd.
- Look here https://msdn.microsoft.com/en-us/library/office/ff844793.aspx and pay particular attention to the last comment on the Range parameter row of the explanatory table. If I read right and you are trying to export to Excel, I think you will find your problem there.
Again, without any clues about error messages or responses, I'm guessing. You could also have referenced the wrong Excel version and may have two issues - one that hasn't been arrived at yet.
 
Upvote 0

Forum statistics

Threads
1,213,504
Messages
6,114,016
Members
448,543
Latest member
MartinLarkin

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