求一段Wincc使用QueryTables方法将SQL内容快速导出到EXCEL的语句。谢谢!琢磨了半天没成功。
最佳答案
亲测可行!
Dim Conn,sql,connstring,record,objExcel,objBook,objSheet,objExcelQuery
Set conn = Createobject("ADODB.connection")
conn.connectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\X\Desktop\LS\111\FGWL.accdb;Persist Security Info=False"
conn.CursorLocation = 3
conn.open
Set record = Createobject("ADODB.recordset")
record.open "select * from m_tb" , conn
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = FalSE
Set objBook = objExcel.Workbooks.Add
Set objSheet = objBook.Worksheets.Add
Set objExcelQuery = objSheet.QueryTables.Add (record, objsheet.range("H13"))
With objExcelQuery
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh
End With
objBook.SaveAs "C:\Users\X\Desktop\1.xlsx"
objExcel.Visible = TrUE
图片说明:
提问者对于答案的评价:
谢谢!
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc317227.html