Sub SaveToMySQL()
Dim conn As Object
Dim cmd As Object
Dim rs As Object
Dim strSQL As String
Dim rng As Range
Dim cell As Range
' Set up the MySQL connection
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = "DRIVER={MySQL ODBC 8.0 Unicode Driver};SERVER=your_server;DATABASE=your_database;USER=your_username;PASSWORD=your_password;"
conn.Open
' Set the range of cells containing the data to be saved
Set rng = ThisWorkbook.Worksheets("Sheet1").Range("A1:C10")
' Prepare the SQL statement
strSQL = "INSERT INTO your_table (column1, column2, column3) VALUES (?, ?, ?)"
' Create the command object
Set cmd = CreateObject("ADODB.Command")
cmd.ActiveConnection = conn
cmd.CommandText = strSQL
cmd.CommandType = 1 ' adCmdText
' Loop through each cell in the range and insert the data into the MySQL table
For Each cell In rng
cmd.Parameters.Append cmd.CreateParameter(, 200, 1, Len(cell.Value), cell.Value)
cmd.Parameters.Append cmd.CreateParameter(, 200, 1, Len(cell.Offset(0, 1).Value), cell.Offset(0, 1).Value)
cmd.Parameters.Append cmd.CreateParameter(, 200, 1, Len(cell.Offset(0, 2).Value), cell.Offset(0, 2).Value)
cmd.Execute
cmd.Parameters.DeleteAll
Next cell
' Close the connection
conn.Close
Set conn = Nothing
End Sub