Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Search replace in word including EOF char

Options
  • 22-09-2004 11:56am
    #1
    Moderators, Arts Moderators Posts: 35,471 Mod ✭✭✭✭


    Not strictly speaking a programming question, but I'm tring to write a macro in Word which needs to recognise the end of the file/document in wildcard search/replace mode. I've read loads of documentation but none mention a possible character for EOF.

    If there is no such searchable character, can anyone think of a better way to, say: highlight the last paragraph of the document?


Comments

  • Moderators, Politics Moderators Posts: 39,765 Mod ✭✭✭✭Seth Brundle


    Haven't time to search or try an example for you but try looking on http://www.electriceditors.net/macros/word/


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 91,686 Mod ✭✭✭✭Capt'n Midnight


    word is a document editor.
    correct me if I am wrong but it does not read past the first EOF (char 00 or 26 ??) so kinda pointless.

    in EDIT (dos program etc.) you can insert characters with control P and then the character - other editors might be similar for recording the macro.

    I've seen one app that treated control-H, backspace key, and Alt (keypad) 8 differently - so you could have fun setting up the macro.

    I'm sure it could be done in VBA by reading in evey byte in the file and changing the EOF's to another character - ie. you don't use file/open at all.


    To highlight last paragraph
    crtl end (or whatever to go to bottom of file)
    search backwards for paragraph character (view them)
    select to end (shift ctrl end or whatever)
    then higlight it


  • Moderators, Arts Moderators Posts: 35,471 Mod ✭✭✭✭pickarooney


    I had to shelve this as it was taking more time to figure the macro out than to do it by hand. I'll probably have to do it again soon, though. Maybe if I explain it in more detail someone might see a way of doing it.

    Basically I have a large log file in .rtf format, much of the information in which is useless. I want to discard anything that doesn't resemble this
    [1] Error - An error occured in paragraph 17, at line 4:
    +++++++++++++++++++++Source++++++++++++++++++++++
    some source text here
    +++++++++++++++++++++Target++++++++++++++++++++++
    some target text here
    ++++++++++++++++++++++++++++++++++++++++++++++++
    
    
    

    In all cases except where such a block of text occurs at the end of the file, the block is followed by three newline characters, so highlighting these section, and then discarding the rest is easy. However, when it's the last bit of text in the file, there is only one newline character, so the search doesn't pick it up. (if I search for only one newline character, it picks up far too much extraneous text).

    So on the first pass I need it to select:
    [num] Error (*) Target(*)+++^p^p^p (block with three newlines) OR
    [num] Error (*) Target(*)+++^pEOF (block + newline + nothing else)

    ...I've just discovered something which makes this unnecessary - there's an option to output a sum-up message at the end of the log file, so I won't ever have an error right at the end... So I'll be using that, then! :)


  • Closed Accounts Posts: 8,264 ✭✭✭RicardoSmith


    Word has its own object model that you can use in VBA. So you can loop through all the paragraph objects in a document, do a count and then process the last one seperately. Its actually very easy to do what you asked in VBA, once you are familar with the object model and its quirks. Same with all VBA enabled applications. I've quite a experience of Word VBA so if your stuck with anything like this just PM me.

    VBA is essentially the same as VB but with specific object model for each app. You can write VBA within VB too. IN fact you can just load Word, or Excel as object within VB itself, if thats what you wanted to do.

    Its quite powerful. While many consider writing macros not programming, but in fact you can code in VBA the same way as you would in VB. Most people never get beyond the 5% of what it can do.


Advertisement