none
Do Until EOF(1) RRS feed

  • Question

  • This  Visual Basic for Applications (VBA) Language Reference for Office 2010 macro does not work.  I want it to test for the end of the open Work 2010 document.  Once it finds the end of the document, I want it to stop executing the statements.  Do you have to identify the physical file name for EOF(1)?  Office help does not provide any useful details on this EOF function.

        Do Until EOF(1)
            Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormCheckBox
            Selection.TypeText Text:=" "
            Selection.MoveDown Unit:=wdLine, Count:=1
            Selection.HomeKey Unit:=wdLine
        Loop

    I'd appreciate any help.  Thanks,

    Bill

    Tuesday, July 23, 2013 3:55 PM

Answers

  • HI Bill

    The Word object model has no End of File concept, as such. Selection.HomeKey does return information that you can use in order to test whether the selection was actually able to move. If it couldn't, then you'd be at the end of the document.

    From the Help:
    "... This method returns an integer that indicates the number of characters the
    selection was actually moved, or it returns 0 (zero) if the move was
    unsuccessful."


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, July 23, 2013 6:25 PM
    Moderator