Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Excel automation - New sheet with ODBC (MySQL) connection

$
0
0
Anyone can explain/help me why this code fails?
I get an "==> The requested action with this object has failed.:" Error and the COM Error states that only object type variables can be used in with statement.

How can i convert the $DBString so that this connection/update works?

The same code in Excel VB does work, and there the connection "String" is working.

#include <Excel.au3>
$oExcel = _ExcelBookNew()
Dim $DBString = "ODBC;DRIVER={MySQL ODBC 5.2w Driver};UID=USER;Pwd=PASS;SERVER=SERVER.IP;DATABASE=DB;PORT=3306;DefaultTable=TABLE"
Dim $Query = "SELECT * FROM `TABLE`"
Dim $TableName = "TABLE"
ConsoleWrite($oExcel.ActiveSheet.Name & @CRLF)
With $oExcel.ActiveSheet.ListObjects.Add(0, $DBString, $oExcel.Range("$A$1") ).QueryTable
.CommandText = $Query
.PreserveFormatting = True
.ListObject.DisplayName = $TableName
.SavePassword = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = 1
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.RowNumbers = False
.FillAdjacentFormulas = False
EndWith


Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>