Import Help

  • Thread starter auujxa2 via AccessMonster.com
  • Start date
A

auujxa2 via AccessMonster.com

The code I have below, is supposed to import all sheets within all workbooks
from a files list that I have. But it seems it repeats importing the first
page over and over for each workbook. Someone please help!!! Thank you in
advance. I commented out the code that I THINK is giving me the problem. I
would think that "for each sht" should be enough, but i think i need to
define the sht where the range is "T4:AF56"

Dim dbs As Database, rst As Recordset
Dim myPath As String
Dim myCount As Variant
Dim myFile As String
Dim SQL As String
Dim wkb As Excel.Workbook
Dim sht As Excel.WorkSheet
Dim xl As Excel.Application

myCount = 0
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("Files")
Set xl = Excel.Application
xl.Visible = False
xl.DisplayAlerts = False

With rst
Do While Not rst.EOF
myCount = myCount + 1
myPath = rst.Fields("FPath")
myFile = rst.Fields("FName")
Set wkb = xl.Workbooks.Open(myPath & myFile, , False)
With wkb
For Each sht In .Worksheets
SysCmd acSysCmdSetStatus, "Importing sheet " & sht.Name & " from
file " & myFile
''''''''''''''''''''''''DoCmd.TransferSpreadsheet acImport, 8, "MasterTable",
myPath & myFile, False, "T4:AF56"
SQL = "UPDATE MasterTable"
SQL = SQL & " SET F1 = '" & myFile & "'"
SQL = SQL & " WHERE F1 Is Null"
dbs.Execute SQL
SQL = "UPDATE MasterTable"
SQL = SQL & " SET F2 = '" & sht.Name & "'"
SQL = SQL & " WHERE F2 Is Null"
dbs.Execute SQL
Next
xl.Workbooks.Close
End With
rst.MoveNext
Loop
rst.Close
End With
Set wkb = Nothing
xl.DisplayAlerts = True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top