Copying from Access. Pasting to Excel

shlobodon

New Member
Joined
Oct 15, 2015
Messages
40
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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Micron

Well-known Member
Joined
Jun 3, 2015
Messages
3,302
Office Version
  1. 365
Platform
  1. Windows
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,043
Messages
5,835,097
Members
430,341
Latest member
kelstnmate

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
Top