Results 1 to 2 of 2

vba code to write values to excel cells

Threaded View

  1. #1
    Registered User
    Join Date
    11-18-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2003, Excel 2013
    Posts
    1

    vba code to write values to excel cells

    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
    Last edited by Anthony.h; 11-18-2013 at 06:26 AM. Reason: making code easier to read

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Write a code to put value copy two tyms and columb values to row
    By pranav.y in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-21-2013, 08:25 AM
  2. How to format a code to write values to create a text file?
    By DakotaRoss in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-08-2013, 09:13 AM
  3. Code to write formula in 2 cells, copy, paste values, repeat next row until end of sheet
    By Oly Steel Man in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-14-2013, 11:13 AM
  4. How do I write code to preserve variables values for future use.
    By Paul in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-12-2005, 12:25 PM
  5. Combining Cells-write a code to get both values
    By Greg B... in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-27-2005, 12:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1