Using a variable as label RRS feed

  • Question

  • I am a total novice to Visual Basics, so help please.

    I have over 400 rows in an excel sheet where I need to transfer the content of individual cells to word tables, one table for each row.

    Each table contains ActiveX labels ("EvtName" and "Group") that relate to the cells, but when I copy the tables in Word the labels increment by 1:  "EvtName1", "EvtName2", etc.

    Coding looks like this

    ThisDocument.EvtName.Caption = exWb.Sheets("").Cells(CT, 4)
    ThisDocument.Group.Caption = exWb.Sheets("").Cells(CT, 2)

    It works perfectly but only for the first table, unless I copy the VBA statements and manually increment the labels, which is what I hope I can avoid.

    Is there a way whereby I can include the variable "CT" in the labels and then run a simple "For - Next" to populate my tables?

    Monday, January 13, 2020 1:10 PM

All replies

  • I would try a mail merge instead, parsing out the data from the Excel sheet into new 'tables'

    Monday, January 13, 2020 10:32 PM
  • Nice suggestion, but all I get is Word collapsing and refusing to do as suggested.

    It is interesting that Visual Basic is unable to handle variables in label captions. Now I know for next time.

    Tuesday, January 14, 2020 11:52 AM