Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Jul 2003
    Park City, Utah
    Thanked 0 Times in 0 Posts

    More Assigning Variable Contents (Word XP VBA)

    Okay, now I am in a cell in a table. What syntax do I use to assign the contents of the current cell to a variable?

    Sorry, I looked all over for this and am too tired or too dense to figure it out.

    Your forever meek and weak newbie VBA programmer,


  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 94 Times in 90 Posts

    Re: More Assigning Variable Contents (Word XP VBA)

    Hopefully we can break you out of your cell!

    If you mean that your insertion point is inside a cell, then you can refer to your cell using


    that is, the first cell in the collection of cells in the Selection. You can refer to its contents using


    But you will notice that a two character "end of cell marker" appears at the end of your range. Bummer. Thus, something like this is needed:

    strCellContents = Left(Selection.Cells(1).Range.Text, Len(Selection.Cells(1).Range.Text) - 2)

    To pick up everything but the last two characters. If you are not in a cell, then the above will give you an error. We had a thread once where we discovered that


    could be true but that the insertion point might not be in a real cell, but at the "end of row" marker. I don't remember the solution we came up with, but if you're in a situation where errors are intolerable and you've confirmed that the selection definitely is within a table, you could use this to make sure you are in a cell:

    Selection.Cells.Count > 0

    Hope this helps.

Posting Permissions

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