Solved IMPORT EXCEL FILE TO ACCESS TABLE (1 Viewer)

georg0307

Registered User.
Local time
Tomorrow, 00:33
Joined
Sep 11, 2014
Messages
91
Dear All,

I need to import data to an Access table only certain Excel range ( Attached the pdf image of excel file).

I am newbie, for this matter.

Could you please help with the VBA code to use for this case?

Many thanks in advance,

Best regards,

Georg
 

Attachments

  • Test_1.pdf
    38.2 KB · Views: 103

theDBguy

I’m here to help
Staff member
Local time
Today, 15:33
Joined
Oct 29, 2018
Messages
21,453
Hi. Sorry can't look at your file right now, but have you tried the TransferSpreadsheet method?

Sent from phone...
 

georg0307

Registered User.
Local time
Tomorrow, 00:33
Joined
Sep 11, 2014
Messages
91
Hi,

thank you for prompt reply.

I added the *.zip file of the original Excel file.

I don't know how to add excel specific ranges (not homogeneous, but fixed) , to specific fields of the access table.

I attached an image (IMPORT_EXCEL.pdf) of what I need.

I hope this draw is clear.

Georg
 

Attachments

  • Test_1.zip
    13.7 KB · Views: 90
  • IMPORT_EXCEL.pdf
    141.9 KB · Views: 102

bastanu

AWF VIP
Local time
Today, 15:33
Joined
Apr 13, 2010
Messages
1,402
You will need to use Excel automation for that, or easier you could add a sheet in your Excel file where you build a list with the first row as the field names and second the values. That sheet can then be very easily imported in Access using the TransferSpreadsheet method.
Cheers,
Vlad
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:33
Joined
Feb 19, 2002
Messages
43,214
If you have a named range, TransferSpreadsheet can import the specified range. Otherwise, as the others have said, you will need to use OLE automation.
 

bastanu

AWF VIP
Local time
Today, 15:33
Joined
Apr 13, 2010
Messages
1,402
Have a look at the attached files, using the Access db you can import the DataList sheet in the modified Excel file.

Cheers,
Vlad
 

Attachments

  • Test_1_Vlad.zip
    41.2 KB · Views: 87

georg0307

Registered User.
Local time
Tomorrow, 00:33
Joined
Sep 11, 2014
Messages
91
DearAll,

Thanks to all.

I will try, with your suggestions.

Best regards.
 

georg0307

Registered User.
Local time
Tomorrow, 00:33
Joined
Sep 11, 2014
Messages
91
Have a look at the attached files, using the Access db you can import the DataList sheet in the modified Excel file.

Cheers,
Vlad
Hi,

I cannot modify named ranges in the Excel file, or any other feature of the same.
The file is as the last I sent.
I think I need something different, OLE automation may be a solution, but it is something out of my knowledge.
Could you help me with this, is there any other way?

Thanks in advance,
Georg
 

ebs17

Well-known member
Local time
Tomorrow, 00:33
Joined
Feb 7, 2020
Messages
1,934
Look at that:
Code:
Sub Import_XLData(ByVal XLFile_FullPath As String)
    Dim rs As DAO.Recordset
    Dim oXL As Object
    Dim oWB As Object

    Set rs = CurrentDb.OpenRecordset("PIR_TABLE", dbOpenDynaset)

    Set oXL = CreateObject("Excel.Application")
    Set oWB = oXL.Workbooks.Open(XLFile_FullPath)
    With oWB.worksheets("ISSUES")
        rs.AddNew

        rs.Fields("RIP") = .Range("B8").Value         ' possibly still type conversion
        ' ... other fields

        rs.Update
        rs.Close
    End With

    oWB.Close SaveChanges:=False
    oXL.Quit

    Set oWB = Nothing
    Set oXL = Nothing
    Set rs = Nothing
End Sub

Eberhard
 

georg0307

Registered User.
Local time
Tomorrow, 00:33
Joined
Sep 11, 2014
Messages
91
Look at that:
Code:
Sub Import_XLData(ByVal XLFile_FullPath As String)
    Dim rs As DAO.Recordset
    Dim oXL As Object
    Dim oWB As Object

    Set rs = CurrentDb.OpenRecordset("PIR_TABLE", dbOpenDynaset)

    Set oXL = CreateObject("Excel.Application")
    Set oWB = oXL.Workbooks.Open(XLFile_FullPath)
    With oWB.worksheets("ISSUES")
        rs.AddNew

        rs.Fields("RIP") = .Range("B8").Value         ' possibly still type conversion
        ' ... other fields

        rs.Update
        rs.Close
    End With

    oWB.Close SaveChanges:=False
    oXL.Quit

    Set oWB = Nothing
    Set oXL = Nothing
    Set rs = Nothing
End Sub

Eberhard

Hi,
Thanks in advance, let's try and let you know.
 

bastanu

AWF VIP
Local time
Today, 15:33
Joined
Apr 13, 2010
Messages
1,402
Here you go.
Cheers,
Vlad
 

Attachments

  • Test_1_vlad_Feb26_2020.zip
    32.4 KB · Views: 111

georg0307

Registered User.
Local time
Tomorrow, 00:33
Joined
Sep 11, 2014
Messages
91
Hi Vlad,

sorry for late answer but here in Italy as you know per News we have some CoronaVirus problems. Only to say thank you very much this code is perfect for me.

Georg
 

bastanu

AWF VIP
Local time
Today, 15:33
Joined
Apr 13, 2010
Messages
1,402
You're very welcome Georg, good luck to you guys,unreal what's happening, last fall we were in Venice, Bologna,Florence and its is heart-breaking to see the impact of the virus now.
Cheers,
Vlad
 

Users who are viewing this thread

Top Bottom