Hi all. below is a copy of my vba code. I have an application from Rockwell automation called, factory talk view. Its object orientated software for displaying values and status of real plant time operation. Any way, it has a built in vba editor. I have setup the following vba code, to allow the two tag objects named "tag1" and "tag2", to be written to the cells A1 and B1. when "button4_relased" function occurs, the vba code executes, excel opens, writes the defined tag object values to the cells, saves the spreadsheet, then excel closes. This operates fine, but I need to change this so each time the function is called, the tag values are written to the next row, and not over A1 & B1 constantly. I can change .cells(1, "A") so 1 becomes a variable, but how do I read what the last empty cell is in the column? help please 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
Bookmarks