locked
Function to return a Row in Word 2010? RRS feed

  • Question

  • Hi all!

    I am relatively new to VBA, but a pretty veteran programmer.

    I need a function to return a Row from a table in Word 2010. My problem is that the VBA Ieditor doesn't recognize the object Row!

    I'm trying something like this:

    private function getRow() as Row

    end function

    but, the VBA editor changes it to:

    private function getRow() as row   '<-- Notice the missing capital 'R'

    end function

    which results in error when I try to execute the macro.

    Anyone have any ideas on how to fix this?

    Best regards

    /Jörgen

    Thursday, June 21, 2012 8:42 AM

All replies

  • I doubt VBA function can return the VBA data types only(String,Long etc) .The row object is defined in Word Object model.

    Will you try below:

    private function getRow() as Long

    end function

    Thursday, June 21, 2012 9:54 AM
    Answerer
  • Hi and thanks for answering!

    I guess I wasn't totally clear in my question.

    So, here's some code for the function, but the problem is still that VBA doesn't recognize the object Row.

    function getRow() as row   '<-- First problem

    dim x as row  '<-- Second problem, actually just for showing the error, not used

    set getRow = ActiveDocument.Tables(1).Rows(1)

    end function

    Hope this clarifies things.

    Best regards

    /Jörgen

    Thursday, June 21, 2012 10:14 AM
  • I tried in Word 2007 and found it working (It is interseting use of function)

    In a blank word - Iinserted Standard Module-Pasted your code.

    Inserted one table with sufficient row.

    then in immediate window used Msgbox getRow.Borders.Count [As getRow is returning row I used one property of row object] and correctly it returned.

    ---------------------------------------------------------------------------------------------

    Please do not forget to click “Vote as Helpful” if any post helps you and mark as Answer if it solves the issue.

    Thursday, June 21, 2012 11:01 AM
    Answerer
  • Because there can be more than one type of Object whose type name is "row", (e.g. you may have defined a Class Module called "row", you may need to qualify "Row", e.g. by defining your function as

    private function getRow() as Word.Row



    Peter Jamieson

    Friday, June 29, 2012 10:21 PM