anthony.h
Member
Hello All, I currently have installed a Compact Logix L35E and Factory Talk View SE on a Scada PC. Question I have is regarding FTView SE and Vba with Excel. I have some VB.net experience but not much. I need to append four different analogue measurements to a excel spreadsheet every 15 minutes. I have searched the web and found vba snippets and have the following code below working ok. On a button press, excel will open, write the tag values to the specific cells, save and close. this is fine, but I need to increment or point to the next empty cell when writing the next set of tags. I can not keep over writing the current cells like I currently am, Does anyone have any vba code or clues as to do this?
Thanks Anthony
Private Sub Button4_Released()
Dim ObjExcelApp As Object
Dim Fname As String
Set MyTagGroup = Application.CreateTagGroup(Me.AreaName)
MyTagGroup.Add "system\Year"
MyTagGroup.Add "[SWTP_PLC001]A30AIT001.Ntu"
Dim SourceErrFile, DestErrFile
Dim Tag1 As Tag
Dim Tag2 As Tag
Dim Mytime
'Set the tag objects
Set Tag1 = MyTagGroup.Item("system\Year")
Set Tag2 = MyTagGroup.Item("[SWTP_PLC001]A30AIT001.Ntu")
Fname = "C:\Users\7 User\Documents\test.xls" '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.ActiveWorkbook.Save
ObjExcelApp.Workbooks.close
ObjExcelApp.Quit
Set ObjExcelApp = Nothing
Exit Sub
End Sub
Thanks Anthony
Private Sub Button4_Released()
Dim ObjExcelApp As Object
Dim Fname As String
Set MyTagGroup = Application.CreateTagGroup(Me.AreaName)
MyTagGroup.Add "system\Year"
MyTagGroup.Add "[SWTP_PLC001]A30AIT001.Ntu"
Dim SourceErrFile, DestErrFile
Dim Tag1 As Tag
Dim Tag2 As Tag
Dim Mytime
'Set the tag objects
Set Tag1 = MyTagGroup.Item("system\Year")
Set Tag2 = MyTagGroup.Item("[SWTP_PLC001]A30AIT001.Ntu")
Fname = "C:\Users\7 User\Documents\test.xls" '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.ActiveWorkbook.Save
ObjExcelApp.Workbooks.close
ObjExcelApp.Quit
Set ObjExcelApp = Nothing
Exit Sub
End Sub