Hello,
I have an Excel 2007 macro enabled file (xlsm) that has records in which the number of rows will change each week.
The file has 3 tabs, each need to be imported into a separatte table. Each tab has a fixed number of columns
tab1 Shipment Tracker into tblShipmentTracker
There are 46 columns that need to be transferred into the 46 corresponding fields in the Access table
I do have a dynamic named range in the Shipment Tracker tab which is called 'Shipment_Import
tab2 Cost into tblCost
There are 51 colulmns that need to be transferred into the 51 corresponding fields in the Access table
tab3 Invoice Tracker into tblInvoiceTracker
There are 65 colulmns that need to be transferred into the 65 corresponding fields in the Access table
I am running into issues of formatting and automating the import into an existing table.
I have found the below code but am not sure how to use it correctly.
I have gotten to the line "Set wb = Workbooks.Open(FN, True, True)" successfully, after that I get this error:
"Runtime Error 1004"
"Application defined or object defined error"
when I debug, it highlights the following line:
Do Until wb.Worksheets("Shipment Tracker").Range("Shipment_Import_Range").Formula = ""
Code Start:
"Sub GetDataFromClosedWorkbook()
Dim wb As Workbook
Dim db As Database, rec As Recordset
'Dim wb As Workbook
Dim x As String, y As String, z As String
Dim A As String, B As String, C As String
Set db = CurrentDb
Set rec = db.OpenRecordset("tblShipmentTracker")
Dim FN As String
FN = "C:\Documents and Settings\KPA004\Desktop\DYNCORP\Standard Template\Dyncorp_Standard_Template_Inbound_v6.xlsm"
'Forms!mainmenu!Child2.Form!MyDirectory & Forms!mainmenu!Child2.Form.Form!mycombobox
Set wb = Workbooks.Open(FN, True, True)
' open the source workbook, read only
Do Until wb.Worksheets("Shipment Tracker").Range("Shipment_Import_Range").Formula = ""
x = wb.Worksheets("Shipment Tracker").Range(A).Formula
y = wb.Worksheets("Sheet1").Range(B).Formula
z = wb.Worksheets("Sheet1").Range(C).Formula
rec.AddNew
rec.Fields("Field1") = x
rec.Fields("Field2") = y
rec.Fields("Field3") = z
rec.Update
i = i + 1
A = "A" & i
B = "B" & i
C = "C" & i
Loop
wb.Close False ' close the source workbook without saving any changes
Set wb = Nothing ' free memory
rec.Close
db.Close
End Sub"
Code END
I have an Excel 2007 macro enabled file (xlsm) that has records in which the number of rows will change each week.
The file has 3 tabs, each need to be imported into a separatte table. Each tab has a fixed number of columns
tab1 Shipment Tracker into tblShipmentTracker
There are 46 columns that need to be transferred into the 46 corresponding fields in the Access table
I do have a dynamic named range in the Shipment Tracker tab which is called 'Shipment_Import
tab2 Cost into tblCost
There are 51 colulmns that need to be transferred into the 51 corresponding fields in the Access table
tab3 Invoice Tracker into tblInvoiceTracker
There are 65 colulmns that need to be transferred into the 65 corresponding fields in the Access table
I am running into issues of formatting and automating the import into an existing table.
I have found the below code but am not sure how to use it correctly.
I have gotten to the line "Set wb = Workbooks.Open(FN, True, True)" successfully, after that I get this error:
"Runtime Error 1004"
"Application defined or object defined error"
when I debug, it highlights the following line:
Do Until wb.Worksheets("Shipment Tracker").Range("Shipment_Import_Range").Formula = ""
Code Start:
"Sub GetDataFromClosedWorkbook()
Dim wb As Workbook
Dim db As Database, rec As Recordset
'Dim wb As Workbook
Dim x As String, y As String, z As String
Dim A As String, B As String, C As String
Set db = CurrentDb
Set rec = db.OpenRecordset("tblShipmentTracker")
Dim FN As String
FN = "C:\Documents and Settings\KPA004\Desktop\DYNCORP\Standard Template\Dyncorp_Standard_Template_Inbound_v6.xlsm"
'Forms!mainmenu!Child2.Form!MyDirectory & Forms!mainmenu!Child2.Form.Form!mycombobox
Set wb = Workbooks.Open(FN, True, True)
' open the source workbook, read only
Do Until wb.Worksheets("Shipment Tracker").Range("Shipment_Import_Range").Formula = ""
x = wb.Worksheets("Shipment Tracker").Range(A).Formula
y = wb.Worksheets("Sheet1").Range(B).Formula
z = wb.Worksheets("Sheet1").Range(C).Formula
rec.AddNew
rec.Fields("Field1") = x
rec.Fields("Field2") = y
rec.Fields("Field3") = z
rec.Update
i = i + 1
A = "A" & i
B = "B" & i
C = "C" & i
Loop
wb.Close False ' close the source workbook without saving any changes
Set wb = Nothing ' free memory
rec.Close
db.Close
End Sub"
Code END