目标:连接MySQL查找数据放入新建Excel表
实现过程:
1.连接数据库
首先要去MySQL官网下载个ODBC数据源。
安装之后,即可在控制面板-管理工具-ODBC数据源-添加,中看到MySQL驱动名称:
'连接数据库
StrCnn="Provider=MSDASQL.1;Persist Security Info=True;Extended Properties='Driver=MySQL ODBC 5.3 Unicode Driver;SERVER=188.1.1.132;UID=grute;PWD=grute;DATABASE=grute;PORT=3307'"
Set Cnn = CreateObject("ADODB.Connection")
Cnn.Open strCnn
'查看是否连接成功,成功状态值为1
If Cnn.State = 0 Then
msgbox "连接数据库失败"
wscript.quit
End If
2.连接Excel
'连接Excel
dim oExcel,oWb,oSheet
Set oExcel= CreateObject("Excel.Application