Import .xlsx files.

Infinite

More left to learn.
Local time
Yesterday, 23:28
Joined
Mar 16, 2015
Messages
402
Hello! How would I go about importing .xlsx files? I want a code that would do this. Something the user can just click, and it would import him the .xlsx file. The way im getting the .xlsx file is from this code:


Code:
Private Sub Command10_Click()
Dim csvFile As String
Dim txtFile As String
Dim xlsxFile As String

csvFile = Dir("C:\Users\Joshua\Downloads\!Import Sales From Online\*.csv")
txtFile = Dir("C:\Users\Joshua\Downloads\!Import Sales From Online\*.txt")
xlsxFile = Dir("C:\Users\Joshua\Downloads\!Import Sales From Online\*.xlsx")

If Len(Dir("C:\Users\Joshua\Downloads\!Import Sales From Online\*.csv")) = 0 Then
   MsgBox "There are NO .csv file(s)."
Else
   MsgBox "There is a .csv file."
   End If
   
If Len(Dir("C:\Users\Joshua\Downloads\!Import Sales From Online\*.txt")) = 0 Then
      MsgBox "There are NO .txt file(s)."
Else
   MsgBox "There is a .txt file."
End If

If Len(Dir("C:\Users\Joshua\Downloads\!Import Sales From Online\*.xlsx")) = 0 Then
      MsgBox "There are NO .xlsx file(s)."
Else
   MsgBox "There is a .xlsx file."
End If

End Sub

That is the code the get the file. Now all I have to figure out is how to import them.

1: The format would be the same for all of the imports
2: There should only be a max of 3 files with different headers and such.
3: I need that imported into a table. I plan on using a update query to update my sales table. That way the user can import the sales with a click of a button.
4: I want access to delete the file when it imports it. That way there are not 3 .xlsx files. !DONE!

Those are the 4 highlights. I should be able to figure out how to delete a file myself, and the format should be fine. I just dont know how to import.

Thanks for all your help!

EDIT: I want it hard imported into my database. Not just attached, or linked.
 
Last edited:
1. you can do this without ANY code. Attach the xl files as a table, run an import query.
Then the next time you get xl files to import , overwrite the old ones and import again.

2. if you MUST use code, delete the file using KILLFILE sFilename
 
1. you can do this without ANY code. Attach the xl files as a table, run an import query.
Then the next time you get xl files to import , overwrite the old ones and import again.

Yes, but I was hoping to do it WITH code. Is there any way for that?
2. if you MUST use code, delete the file using KILLFILE sFilename


Code:
Private Sub Command53_Click()
Dim LResponse As Integer
Dim FilePath As String


FilePath = Dir("C:\Users\Joshua\Downloads\!Import Sales From Online\*.csv")


LResponse = MsgBox("Are you sure you want to delete the file " & FilePath & "" & _
vbCrLf & "Warning! This will delete it PERMANENTLY! (A really really long time)" _
, vbYesNo, "FOR. EVER.")
If LResponse = vbYes Then
   On Error Resume Next
    Kill "C:\Users\Joshua\Downloads\!Import Sales From Online\*.csv*"
    On Error GoTo 0
    Else
    
End If
End Sub

I have the kill code here already. I just need to import.
 
Any one found anything? I have been looking some more, but to no avail.
 

Users who are viewing this thread

Back
Top Bottom