FactoryTalk View SE VBA Tags to Excel

I got where was problem. I written script in module, as i made it b4 in rsview 32. There is lot difference between rsview32 & ftview VB.

Now i want that how i can run VB at specific event in ftview se. IN rsview 32 i did that as added executevb in event. But here in ftview no option available to run VB. can u plz help me to how to run VB at specific event(tag ON bit)??

:unsure:
 
Option Explicit

Dim tkqt As New ADODB.Recordset
Dim MyTAgGroup1 As TagGroup
Dim t2tag As Tag 'tag object
Dim tkmeasuredQty As String
Dim t1tag As Tag 'tag object


Public Function tankerquantity()
ConnectDB

If MyTAgGroup1 Is Nothing Then
Set MyTAgGroup1 = Application.CreateTagGroup(Me.AreaName, 500)
End If

MyTAgGroup1.Add "system\second"

MyTAgGroup1.Add "SECTION1\TEST1"

Set tkqt = New ADODB.Recordset

With tkqt
.ActiveConnection = adodbcon
.CursorType = 2
.LockType = 2
.Source = "tblLTReport"
.Open
End With
tkqt.MoveLast

Set t1tag = MyTAgGroup1.Item("SECTION1\TEST1")
tkmeasuredQty = t1tag.VALUE
tkqt.Fields!MeasuredQty = tkmeasuredQty
tkqt.Update

End Function



this script is running fine. whether i need to change anything in this, or add anything else.. plz tell me.

also i want to ask that i used rslinx enterprise for communication. so i linked tags directly in graphics(tags not added in HMI tags). But in VB in needed HMI tags. So i want that whether i need to add all tags which i using in VB, in HMI tags. Or any other option is available to link tag in VB(without adding in HMI tags)?????

Sorry to ask all this.. i am new to FTVIEW & i dnt hav more support..
 
Option Explicit

Dim tkqt As New ADODB.Recordset
Dim MyTAgGroup1 As TagGroup
Dim t2tag As Tag 'tag object
Dim tkmeasuredQty As String
Dim t1tag As Tag 'tag object


Public Function tankerquantity()
ConnectDB

If MyTAgGroup1 Is Nothing Then
Set MyTAgGroup1 = Application.CreateTagGroup(Me.AreaName, 500)
End If

MyTAgGroup1.Add "system\second"

MyTAgGroup1.Add "SECTION1\TEST1"

Set tkqt = New ADODB.Recordset

With tkqt
.ActiveConnection = adodbcon
.CursorType = 2
.LockType = 2
.Source = "tblLTReport"
.Open
End With
tkqt.MoveLast

Set t1tag = MyTAgGroup1.Item("SECTION1\TEST1")
tkmeasuredQty = t1tag.VALUE
tkqt.Fields!MeasuredQty = tkmeasuredQty
tkqt.Update

End Function



this script is running fine. whether i need to change anything in this, or add anything else.. plz tell me.

also i want to ask that i used rslinx enterprise for communication. so i linked tags directly in graphics(tags not added in HMI tags). But in VB in needed HMI tags. So i want that whether i need to add all tags which i using in VB, in HMI tags. Or any other option is available to link tag in VB(without adding in HMI tags)?????

Sorry to ask all this.. i am new to FTVIEW & i dnt hav more support..

You can write script on Numeric Display Change.

Check this thread http://www.plctalk.net/qanda/showthread.php?t=45273
 
Convert Function to use with event

Hi,
Is there any way that I can use this function in FTView event rather calling on NumericDispaly_Change?


Hi ghatevinod

You Can try Below Script with some modification such as save file path and tags.



Private Sub NumericInput5_Change()
Dim sFileName As String, sPath As String
If MyTagGroup Is Nothing Then
Set MyTagGroup = Application.CreateTagGroup(Me.AreaName)
MyTagGroup.Add "AI\I1"
MyTagGroup.Add "AI\I2"
MyTagGroup.Add "AI\I3"
MyTagGroup.Add "AI\I4"

' On Error GoTo ErrorHandler
Dim SourceErrFile, DestErrFile
Dim Tag1 As Tag
Dim Tag2 As Tag
Dim Tag3 As Tag
Dim Tag4 As Tag

Dim Mytime
'Set the tag objects
Set Tag1 = MyTagGroup.Item("AI\I1")
Set Tag2 = MyTagGroup.Item("AI\I2")
Set Tag3 = MyTagGroup.Item("AI\I3")
Set Tag4 = MyTagGroup.Item("AI\I4")


Excel.Application.Workbooks.Open "C:\resourcelibrary\import.csv"
Excel.Application.Visible = True

Cells(2, 4) = Tag1.Value
Cells(3, 4) = Tag2.Value
Cells(4, 4) = Tag3.Value
Cells(5, 4) = Tag4.Value
ChDir "C:\resourcelibrary"


ActiveWorkbook.SaveAs Filename:="C:\resourcelibrary\Import" & "-" & Format(Now, "dd-mmm-yyyy-hh-mm-ss") & ".xls"


Filename:="C:\resourcelibrary\Import.xls" & Date & " " & Time


ActiveWorkbook.Close



End If
End Sub
 
Thank you guys. Lots of new science in this forum.
o.png
 
Dear Bansodevb,
I need help in SE VBA Code. I got Code for PLC Forum that is working fine.Right Now I want Cells increment Code in vba. Please Help for me. I Have More than 250 Tag.
How to write for above Logic for BMS Application.
I attached that code below
Private Sub Button1_Released()
Dim ObjExcelApp As Object
Dim Fname As String
Set MyTagGroup = Application.CreateTagGroup(Me.AreaName)
MyTagGroup.Add "AI\I1"
MyTagGroup.Add "AI\I2"
MyTagGroup.Add "AI\I5"


Dim SourceErrFile, DestErrFile
Dim Tag1 As Tag
Dim Tag2 As Tag
Dim Tag3 As Tag
Dim Mytime
'Set the tag objects

Set Tag1 = MyTagGroup.Item("AI\I1")
Set Tag2 = MyTagGroup.Item("AI\I2")
Set Tag3 = MyTagGroup.Item("AI\I5")
Fname = "D:\Lord Shiva.xlsx" 'name of already created excel project
Set ObjExcelApp = CreateObject("Excel.Application")
ObjExcelApp.Visible = False
ObjExcelApp.Workbooks.Open (Fname)
ObjExcelApp.WorkSheets("Sheet1").cells(1, "A").Value = Tag1.Value
ObjExcelApp.WorkSheets("Sheet1").cells(1, "B").Value = Tag2.Value
ObjExcelApp.WorkSheets("Sheet1").cells(1, "C").Value = Tag3.Value
ObjExcelApp.ActiveWorkbook.SaveAs Filename:="D:\Lord Shiva" .xlsx"
ObjExcelApp.Workbooks.close
ObjExcelApp.Quit
Set ObjExcelApp = Nothing
Exit Sub
End Sub
Sir Im waiting for your reply
my mail id:[email protected]
Please send relevant cod my mail sir
 
Poderia me Ajudar??

Estou fazendo exatamente como seu codigo descrito abaixo:

Private Sub Button_AlarmAck1_Released()

Dim sFileName As String, sPath As String
If oGroup Is Nothing Then

Set oGroup = Application.CreateTagGroup(Me.AreaName, 500)
oGroup.Add "T1"
oGroup.Add "T2"
oGroup.Add "T3"
oGroup.Add "T4"
oGroup.Active = True

' On Error GoTo ErrorHandler
Dim SourceErrFile, DestErrFile
Dim Tag1 As Tag
Dim Tag2 As Tag
Dim Tag3 As Tag
Dim Tag4 As Tag

'Set the tag objects
Dim Mytime
Set Tag1 = oGroup.Item("T1")
Set Tag2 = oGroup.Item("T2")
Set Tag3 = oGroup.Item("T3")
Set Tag4 = oGroup.Item("T4")

Excel.Application.Workbooks.Open "Z:\Pasta1.csv"
Excel.Application.Visible = True

Cells(2, 4) = Tag1.Value
Cells(3, 4) = Tag2.Value
Cells(4, 4) = Tag3.Value
Cells(5, 4) = Tag4.Value
ChDir "D:\"

ActiveWorkbook.SaveAs Filename:="D:\Import" & "-" & Format(Now, "dd-mmm-yyyy-hh-mm-ss") & ".xls"

'Filename:="D:\Import.xls" & Date & " " & Time

ActiveWorkbook.Close

End If

A linha ->Filename:="D:\Import.xls" & Date & " " & Time
esta me dando erro. Tenho meu excel numa outra maquina por isto da unidade Z:

Meu script esta certo para jogar um valor do supervisorio digitado para uma planilha excel???
 
My Portuguese is a bit rough, if the location doesn’t exist on the computer running the display client and you want to save it elsewhere you can reference the location with its UNC name:

ActiveWorkbook.SaveAs Filename:="\\mycomputer\d$\Import" & "-" & Format(Now, "dd-mmm-yyyy-hh-mm-ss") & ".xls"

Assuming you have a DNS server on your network and permissions to write to the location.
 
Hi NareshKusa, Thankyou for your code.I solved one of the requirement from ur code.

Hi NareshKusa,
Thankyou for your code.I have solved one of the process requirement from your(VBA to Excel) code.
Communication is good.But while execution,one dialog box opened & its showing Read/write access.Every time i have to close manually.is any update is there.
 
I need help with SE VBA code. I am using the VBA code in this forum but it is giving me a compile error: Sub or Function not defined at the tag values write into the cells of the excel spreadsheet. Can anyone please help me with this. I am using FTV SE V12. Below is the code





Private Sub NumericDisplay1_Change()
Dim sFileName As String, sPath As String
If MyTagGroup Is Nothing Then
Set MyTagGroup = Application.CreateTagGroup(Me.AreaName)
MyTagGroup.Add "CLEAN\Test_1"
MyTagGroup.Add "CLEAN\Test_2"
MyTagGroup.Add "CLEAN\Test_3"
MyTagGroup.Add "CLEAN\Test_4"

' On Error GoTo ErrorHandler
Dim SourceErrFile, DestErrFile
Dim Tag1 As Tag
Dim Tag2 As Tag
Dim Tag3 As Tag
Dim Tag4 As Tag

Dim Mytime
'Set the tag objects
Set Tag1 = MyTagGroup.Item("CLEAN\Test_1")
Set Tag2 = MyTagGroup.Item("CLEAN\Test_2")
Set Tag3 = MyTagGroup.Item("CLEAN\Test_3")
Set Tag4 = MyTagGroup.Item("CLEAN\Test_4")


Excel.Application.Workbooks.Open "C:\resourcelibrary\import.csv"
Excel.Application.Visible = True

Cells(1, 1) = Tag1.Value
Cells(1, 2) = Tag2.Value
Cells(1, 3) = Tag3.Value
Cells(1, 4) = Tag4.Value
ChDir "C:\resourcelibrary"


ActiveWorkbook.SaveAs Filename:="C:\resourcelibrary\Import" & "-" & Format(Now, "dd-mmm-yyyy-hh-mm-ss") & ".xls"


Filename:="C:\resourcelibrary\Import.xls" & Date & " " & Time


ActiveWorkbook.Close



End If
End Sub
 
Try this:

Private Sub NumericDisplay1_Change()
Dim ObjExcelApp As Object
Dim Fname As String
Set MyTagGroup = Application.CreateTagGroup(Me.AreaName)
MyTagGroup.Add "CLEAN\Test_1"
MyTagGroup.Add "CLEAN\Test_2"
MyTagGroup.Add "CLEAN\Test_3"
MyTagGroup.Add "CLEAN\Test_4"


Dim SourceErrFile, DestErrFile
Dim Tag1 As Tag
Dim Tag2 As Tag
Dim Tag3 As Tag
Dim Tag4 As Tag

'Set the tag objects
Set Tag1 = MyTagGroup.Item("CLEAN\Test_1")
Set Tag2 = MyTagGroup.Item("CLEAN\Test_2")
Set Tag3 = MyTagGroup.Item("CLEAN\Test_3")
Set Tag4 = MyTagGroup.Item("CLEAN\Test_4")

Fname = "C:\resourcelibrary\import.csv" 'name of already created excel project
Set ObjExcelApp = CreateObject("Excel.Application")
ObjExcelApp.Visible = False
ObjExcelApp.Workbooks.Open (Fname)
ObjExcelApp.WorkSheets("Sheet1").cells(1, "A").Value = Tag1.Value
ObjExcelApp.WorkSheets("Sheet1").cells(1, "B").Value = Tag2.Value
ObjExcelApp.WorkSheets("Sheet1").cells(1, "C").Value = Tag3.Value
ObjExcelApp.ActiveWorkbook.SaveAs Filename:="C:\resourcelibrary\import.csv.xlsx"
ObjExcelApp.Workbooks.close
ObjExcelApp.Quit
Set ObjExcelApp = Nothing

End Sub
 

Similar Topics

I'm creating an HMI that has a recipe with 288 data point. It has 3 pieces of data for 96 segments. I need help with VBA code to copy all 288...
Replies
0
Views
123
Hi, Can someone guide me through how to use FactoryTalk SE VB script to open communication with SQL Server? which command I can use? Are there...
Replies
2
Views
2,248
Hello group, I have been migrating a project from RSView 32 V7.6 to FactoryTalk View SE Local Station V12 over the last couple of days. All told...
Replies
0
Views
991
For trend charts, I can use an ActiveX Calendar control to select a date on a trend using the following code where "Trend" is the name of the...
Replies
2
Views
1,560
Anyone know how to change the mouse icon to something else using VBA? It looks like it can be done with VBA forms and based on the object the...
Replies
0
Views
2,200
Back
Top Bottom