none
Switching Macros from Excel to Word RRS feed

  • Question

  • Hey,
    so I wrote a macro for excel in VBA to fill in labels, and then promptly realized that the template I need to fill into only exists in word. Now I need to convert my code from excel to word. I fixed most of the issues this caused but have two which I am stumped on. I have looked around but cannot seem to find it in the documentation to fix these two lines.


    ActiveCell.Offset(1, 0).Range("A1").Select

    and

    ActiveCell.FormulaR1C1 = other

    The first one is moving me to the next excel cell I want to fill and the second one is filling the cell in. I would like to do the same thing in a table in word. Does anyone know how to do this or if not where in the documentation I could find it?

    Thanks

    Thursday, August 7, 2014 2:47 PM

Answers

  • To select the next cell in a table, you can use

    Selection.Cells(1).Next.Select

    And to set the text of the selected cell, you can use

    Selection.Text = "blah blah"


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Thursday, August 7, 2014 4:05 PM

All replies

  • To select the next cell in a table, you can use

    Selection.Cells(1).Next.Select

    And to set the text of the selected cell, you can use

    Selection.Text = "blah blah"


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Thursday, August 7, 2014 4:05 PM
  • Perhaps you should consider using a Word mailmerge. No VBA required.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, August 8, 2014 2:46 AM
  • Hello,

    You can always use the Macro recorder available in Word. Thus, you can do the required actions manually - the code will be generated automatically for you. See Create or run a macro for more information.

    Also I'd suggest asking Word specific questions in the Word for Developers forum instead.

    Friday, August 8, 2014 8:55 AM
  • You can always use the Macro recorder available in Word. Thus, you can do the required actions manually - the code will be generated automatically for you.

    Sure, one could use the macro recorder, but: (a) there are many actions it won't record; (b) the code it produces is typically bloated way beyond what is needed; (c) it is usually quite inflexible and inefficient; and (d) it would be next to useless for what the OP wants.

    Cheers
    Paul Edstein
    [MS MVP - Word]




    Friday, August 8, 2014 9:35 AM
  • Of course there are some pitfalls, I can agree that it's not a panacea. But before asking any questions I'd suggest using the Macro recorder (where it is available).
    Friday, August 8, 2014 10:36 AM