Created
July 30, 2021 01:16
-
-
Save stevesohcot/11f401679e80241141c5ccb9ea0cd164 to your computer and use it in GitHub Desktop.
VBA Import Data from Excel - Main sub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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