999久久久精品国产消防器材,国产成人久久综合77777,√最新版天堂资源网在线,精品久久久久区二区8888,卡一卡二卡三乱码视频

技成培訓(xùn)網(wǎng) 技成學(xué)習(xí)APP 技成工具箱 技成企業(yè)服務(wù)

歡迎回到技成培訓(xùn)網(wǎng)

技成培訓(xùn)網(wǎng)

電工題庫寶典

技成電工課堂

PLC練習(xí)題

技成PLC課堂

變頻器故障查詢

技成PLC學(xué)吧

伺服驅(qū)動故障查詢

技成PLC網(wǎng)校

當(dāng)前位置:技成首頁 > 文章中心 > 技成百科 > 如何通過vbs在wincc的畫面中寫入excel中r1c1位的字符串

如何通過vbs在wincc的畫面中寫入excel中r1c1位的字符串

劉玉蓉 發(fā)布于2014-10-28 17:42 1 0 標(biāo)簽:

在wincc畫面中建立一個i/o域,如何用vbs腳本寫入(讀出)excel中的數(shù)值,只要有一個位置r1c1的數(shù)值就可以了。
新手,一點方向都沒有
請問:
1、腳本是在全局腳本寫還是在對象屬性寫
2、腳本的基本例子給一個,越詳細(xì)越好
3、鏈接的文本看了不少,沒有方向

佳答案

本人做的源代碼:
Sub OnClick(ByVal Item)                                     
Dim fso,myfile
Set fso = CreateObject("scripting.FileSystemObject")
Set MyFile = fso.GetFile("d:\data.xlsx")
Dim ObjExcelApp
Set objExcelApp = CreateObject("Excel.Application")
"objExcelApp.Visible = True
objExcelApp.Workbooks.Open MyFile
"上面的程序段是為了打開d盤excel文件
Dim aa_data
objExcelApp.worksheets ("sheet1").Cells(2, 9).VAlue = HMIRuntime.Tags("aa").read
Dim i,j
If objExcelApp.worksheets ("sheet1").Cells(2, 9).VAlue>1.0 Then
i=2
j=6
End If
If objExcelApp.worksheets ("sheet1").Cells(2, 9).VAlue>0.8 And  objExcelApp.worksheets ("sheet1").Cells(2, 9).VAlue<1.0 Then
i=7
j=11
End If
If objExcelApp.worksheets ("sheet1").Cells(2, 9).VAlue>0.6 And  objExcelApp.worksheets ("sheet1").Cells(2, 9).VAlue<0.8 Then
i=12
j=16
End If
If objExcelApp.worksheets ("sheet1").Cells(2, 9).VAlue<0.6Then
i=17
j=21
End If
"判斷數(shù)據(jù)保存位置
Do While i<j
objExcelApp.worksheets ("sheet1").Cells(i, 1).VAlue =objExcelApp.worksheets ("sheet1").Cells(i+1, 1).VAlue
objExcelApp.worksheets ("sheet1").Cells(i, 2).VAlue = objExcelApp.worksheets ("sheet1").Cells(i+1, 2).VAlue
i=i+1 
Loop 
objExcelApp.worksheets ("sheet1").Cells(i, 1).VAlue =HMIRuntime.Tags("yy").read
objExcelApp.worksheets ("sheet1").Cells(i, 2).VAlue =HMIRuntime.Tags("xx").read

"寫數(shù)據(jù)到excel表格
objExcelApp.ActiveWorkbook.Save
"保存表格
Dim cons_data,ax1_data,ax2_data,ax3_data,ax4_data,ax5_data,ax6_data
Set cons_data=HMIRuntime.Tags("cons")
Set ax1_data=HMIRuntime.Tags("ax1")
Set ax2_data=HMIRuntime.Tags("ax2")
Set ax3_data=HMIRuntime.Tags("ax3")
Set ax4_data=HMIRuntime.Tags("ax4")
Set ax5_data=HMIRuntime.Tags("ax5")
Set ax6_data=HMIRuntime.Tags("ax6")


cons_data.Value = objExcelApp.worksheets ("sheet1").Cells(23,7).value
ax1_data.Value = objExcelApp.worksheets ("sheet1").Cells(23, 6).value
ax2_data.Value = objExcelApp.worksheets ("sheet1").Cells(23, 5).value
ax3_data.Value = objExcelApp.worksheets ("sheet1").Cells(23, 4).value
ax4_data.Value = objExcelApp.worksheets ("sheet1").Cells(23, 3).value
ax5_data.Value = objExcelApp.worksheets ("sheet1").Cells(23, 2).value
ax6_data.Value = objExcelApp.worksheets ("sheet1").Cells(23, 1).value
"上面的作用是將Excel表格中的數(shù)據(jù)讀到wincc,存到臨時變量里面
objExcelApp.Workbooks.Close
objExcelApp.Quit
Set ObjEXceLapp = Nothing
"到這里為止,關(guān)閉剛才打開的excel程序了
cons_data.Write 
ax1_data.Write 
ax2_data.Write 
ax3_data.Write 
ax4_data.Write 
ax5_data.Write 
ax6_data.Write 
"后是把讀到的excel值從臨時變量中寫入它對應(yīng)的wincc變量中


End Sub

若有收獲,就點個贊吧!

文章來源于網(wǎng)絡(luò)及文獻(xiàn)如有侵權(quán)請聯(lián)系站長
分享到:

微信掃一掃分享

閱讀與本文標(biāo)簽相同的文章

相關(guān)推薦

最新文章 熱門文章
最新課程 免費(fèi)課程
PLC資料下載 電工電氣資料下載
應(yīng)用新秀
變頻器故障代碼查詢APP
伺服故障代碼查詢APP
技成
手機(jī)APP
熱門標(biāo)簽