Naming a tab on an imported spreadsheet

Leesha
BronzeLounger
Posts: 1488
Joined: 05 Feb 2010, 22:25

Naming a tab on an imported spreadsheet

Post by Leesha »

Hi,
I'm using the code below to import data into a DB. The spreadsheet originally came with only on tab named "Data". Now the spreadsheet comes with 3 tabs and the "Data" tab is no longer the first tab in the spreadsheet. I took a shot a entering the name of the sheet in the code but it returns an error that says that the object "data" can't be found. I'm not sure what I am missing.

Thanks,
Leesha


Dim strFolder As String
Dim strFile As String


' Fixed folder path
strFolder = "C:\StoreID\Import\"
' Find filename
strFile = Dir(strFolder & "*.xlsx")
Do While strFile <> ""
If strFile = "" Then
MsgBox "No .xlsx file in folder!", vbExclamation
Exit Sub
End If
' Import VDC weekly sales spreadsheet
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml, _
"tblImportTemp-VDC", strFolder & strFile, True, "Data"



strFile = Dir
Loop

User avatar
HansV
Administrator
Posts: 78500
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Naming a tab on an imported spreadsheet

Post by HansV »

Add an exclamation mark after the sheet name: use "Data!" instead of "Data"
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1488
Joined: 05 Feb 2010, 22:25

Re: Naming a tab on an imported spreadsheet

Post by Leesha »

Thanks Hans! I appreciate you and your help,
Leesha