ImportExportSpreadsheet Macro

Dundee Lad

Active Member
Joined
Sep 6, 2003
Messages
311
Hi Board, I am using access 2013. I am trying to get the ImportExportSpreadsheet Macro to import one of the sheets in a work book. The sheet tab name changes but will always be 'Sheet2'. Do you know what I input into the range field to import this?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
what code have you got so far, pop in here between code tags
 
Upvote 0
macros are VBA code, would be useful to see what you have recorded already
 
Upvote 0
ok just learnt something new!

Code:
Option Compare Database

'------------------------------------------------------------
' Mcr_ImportCosts2
'
'------------------------------------------------------------
Function Mcr_ImportCosts2()
On Error GoTo Mcr_ImportCosts2_Err

    On Error Resume Next
    DoCmd.Hourglass True
    DoCmd.DeleteObject acTable, "Tbl_Costs2"
    DoCmd.TransferSpreadsheet acImport, 10, "Tbl_Costs2", "Q:\Production Database\Tables\Tbl_Costs\2016_17 YTD.xlsx", True, "P1 Capex!"
    DoCmd.OpenQuery "Qry_App_TblCosts2_Tbl_Costs", acViewNormal, acEdit
    DoCmd.Hourglass False


Mcr_ImportCosts2_Exit:
    Exit Function

Mcr_ImportCosts2_Err:
    MsgBox Error$
    Resume Mcr_ImportCosts2_Exit

End Function
 
Upvote 0
macros are VBA code, would be useful to see what you have recorded already
In Access technically macros (Macros capital M) are a feature that uses a gui designer to build custom sets of automated actions and the user does not work directly with vba code. Just an FYI. This can be confusing at times especially for those who come to Access with some Excel vba experience.

Note, and of course now the OP has named his VBA code function a macro lol!
 
Last edited:
Upvote 0
In Access technically macros (Macros capital M) are a feature that uses a gui designer to build custom sets of automated actions and the user does not work directly with vba code. Just an FYI. This can be confusing at times especially for those who come to Access with some Excel vba experience.
Note, and of course now the OP has named his VBA code function a macro lol!
OK common technicality of words (I'm common :) )
Visual Basic for Applications and Excel window is Microsoft Visual Basic and we all know most of those are "macros" in common parlance
 
Upvote 0
I amended the sheet tab name from P1 Capex! to Sheets(2) in the range field but get an error telling me it doesn't recognise
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,525
Members
449,088
Latest member
RandomExceller01

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