Skip to content

Instantly share code, notes, and snippets.

@stevesohcot
Created July 30, 2021 01:16
Show Gist options
  • Select an option

  • Save stevesohcot/11f401679e80241141c5ccb9ea0cd164 to your computer and use it in GitHub Desktop.

Select an option

Save stevesohcot/11f401679e80241141c5ccb9ea0cd164 to your computer and use it in GitHub Desktop.
VBA Import Data from Excel - Main sub
Public Sub autoImport()
' First delete existing data
Dim strSQL As String
strSQL = "DELETE FROM myTableName" ' Could potentially TRUNCATE instead
Call RunSQL(strDbConn, strSQL)
' Import the new data
Call ImportData("tabWithData") ' Be sure to pass in the name of your worksheet, or get it dynamically
' Indicate when the data was updated; I'm using a "utility" table
Dim theDate As String
theDate = InputBox("Enter date that the data for", "Data as of", Format(Now, "m/d/yyyy"))
strSQL = "UPDATE Utility SET value = '" & ReplaceSingleQuote(theDate) & "' WHERE description IN ('Last Updated,'Last Updated')"
Call RunSQL(strDbConn, strSQL)
Range("A1").Select
MsgBox "Data has been imported"
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment