Minnesota Mike
New Member
- Joined
- Apr 1, 2015
- Messages
- 5
I am creating a macro in Excel 2010 that selects a range of data (which changes each month) and copies that range into a table in Access 2010. I am getting the error message "Run-time Error 2498: An expression you entered is the wrong data type for one of the arguments." The macro stops at the DoCmd.TransferSpreadsheet line. I think I have everything defined appropriately but something is a miss. The macro code is shown below. Thanks for input.
Code:
Sub Access_Export_Table()
Dim app_Access As Access.Application
Dim wb As Workbook
Dim wb_Path As String
Dim wb_Name As String
Dim ws As Worksheet
Dim int_Count_Rows As Integer
Dim int_Count_Columns As Integer
Dim rng_Export As Range
Set wb = ActiveWorkbook
wb_Path = wb.Path
wb_Name = wb.Name
Worksheets("Export").Activate
Set ws = ActiveSheet
Range("A1").Select
int_Count_Rows = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
int_Count_Columns = Selection.End(xlToRight).Column
Set rng_Export = Range(Cells(1, 1), Cells(int_Count_Rows, int_Count_Columns))
rng_Export.Select
Set app_Access = Access.Application
Application.ActivateMicrosoftApp xlMicrosoftAccess
app_Access.DoCmd.TransferSpreadsheet _
acImport, _
acSpreadsheetTypeExcel12Xml, _
"Imported Forecast", _
wb_Path & "\" & wb_Name, _
True, _
rng_Export
End Sub
Last edited by a moderator: