I would like to import a file from Excel using vba coding and have been reading posts trying to put something together. I try to run it nothing happens. I'm probably doing something super stupid but I'm just learning so there you go. Here's what I have so far:
Private Sub cmdImportTemplates_Click()
Dim oXLApp As Excel.Application
Dim oXLBook As Excel.Workbook
Dim oXLSheet As Excel.Worksheet
Dim RSSpecialist As Recordset
Dim strSpcTemplate As String
Dim strFolder As String
Dim WB As Workbook
Dim strFileName As String
Dim introw As Long
Dim strSpecialistName As String
Dim rUsed As rangeset
Dim dbs As Database
'to create a temporary table in acess with two fields, breeder and family
Set dbs = OpenDatabase("Copy of Breeder Entry.accdb")
dbs.Execute "CREATE TABLE Temporary" _
& "(Breeder CHAR, Family CHAR);"
dbs.Close
'directing name and location of excel file to import
strFolder = Trim(txtFolder)
If Right(strFolder, 1) <> "\" Then
strFolder = strFolder & "\"
End If
strFileName = Trim(textfilename)
strSpcTemplate = strFolder & strFileName
txtCurrProfile = Null
DoEvents
'define last row with data as this will differ
Set oXLBook = oXLApp.Workbooks.Open(strSpcTemplate)
rUsed = Intersect(Range("A:AR"), ActiveSheet.UsedRange)
introw = oXLSheet.UsedRange.Rows.Count
set strSpecialistName = strSpcTemplate(B:1)
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, temporary, strSpcTemplate, True, "A3:K & introw"
Set oXLSheet = Nothing
oXLBook.Close SaveChanges:=False
Set oXLBook = Nothing
oXLApp.Quit
Set oXLApp = Nothing
MsgBox "Finished Importing Data", vbOKOnly
End Sub
Any input would be helpful! Thanks
Private Sub cmdImportTemplates_Click()
Dim oXLApp As Excel.Application
Dim oXLBook As Excel.Workbook
Dim oXLSheet As Excel.Worksheet
Dim RSSpecialist As Recordset
Dim strSpcTemplate As String
Dim strFolder As String
Dim WB As Workbook
Dim strFileName As String
Dim introw As Long
Dim strSpecialistName As String
Dim rUsed As rangeset
Dim dbs As Database
'to create a temporary table in acess with two fields, breeder and family
Set dbs = OpenDatabase("Copy of Breeder Entry.accdb")
dbs.Execute "CREATE TABLE Temporary" _
& "(Breeder CHAR, Family CHAR);"
dbs.Close
'directing name and location of excel file to import
strFolder = Trim(txtFolder)
If Right(strFolder, 1) <> "\" Then
strFolder = strFolder & "\"
End If
strFileName = Trim(textfilename)
strSpcTemplate = strFolder & strFileName
txtCurrProfile = Null
DoEvents
'define last row with data as this will differ
Set oXLBook = oXLApp.Workbooks.Open(strSpcTemplate)
rUsed = Intersect(Range("A:AR"), ActiveSheet.UsedRange)
introw = oXLSheet.UsedRange.Rows.Count
set strSpecialistName = strSpcTemplate(B:1)
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, temporary, strSpcTemplate, True, "A3:K & introw"
Set oXLSheet = Nothing
oXLBook.Close SaveChanges:=False
Set oXLBook = Nothing
oXLApp.Quit
Set oXLApp = Nothing
MsgBox "Finished Importing Data", vbOKOnly
End Sub
Any input would be helpful! Thanks