+ Reply to Thread
Results 1 to 9 of 9

complicated Help about VBA Find/Replace

  1. #1
    Registered User
    Join Date
    01-11-2017
    Location
    London, England
    MS-Off Ver
    2003,2007,2010,2013
    Posts
    65

    Unhappy complicated Help about VBA Find/Replace

    Hi all,

    well then as i mentioned it is complicated issue but i will be so appreciated to one who can help me about it, as i need that macro badly..


    i have HTML files to deal with and i found that the only way to do what i want is to copy the source code in word then do Find/Replace processes with VBA then back it again to HTML

    1- i want to go through all the word file and look for any paragraph start with "<li id="footnote-"
    2- then Copy the text starts and between with "<a href" to "</a>"
    3- and put it after "<p>" in the same paragraph
    4- then replace the number at the end of paragraph only that is between two brackets to "*"


    for ex:

    here is the line that i wan't the macro to get:

    <li id="footnote-3"><p>XXalso of Virginia. We were extremely lucky <a href="#footnote-ref-3">[2]</a></p></li>
    - the red text should be copied after <p> in the place that has green (XX) existed
    - then replace the number [2] at the end of line to (*)

    final result should be as following

    <li id="footnote-3"><p><a href="#footnote-ref-3">[2]</a> also of Virginia.We were extremely lucky <a href="#footnote-ref-3">*</a></p></li>
    please note that there are no colors in the file, that are only to explain it clear

    i hope that someone can help me guys, i will own to him

    Thanks in advance


    Cross-posting link: http://www.vbaexpress.com/forum/show...A-Find-Replace

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,143

    Re: complicated Help about VBA Find/Replace

    If it doesn't have to be in the word then try it.
    Works fine if there are any errors ?
    You need to save the html file as a text file somewhere on the disk and then run the macro.
    The resulting file will be saved (in the same directory) under the "same name" but with the beginning of "result_", e.g.:
    source file = sourcefile.html.txt
    resulting file = result_sourcefile.html.txt
    Finally, you change the name of file to 'result_sourcefile.html' or some other name.
    Attached Files Attached Files
    Last edited by mjr veverka; 10-14-2017 at 11:14 PM.

  3. #3
    Registered User
    Join Date
    01-11-2017
    Location
    London, England
    MS-Off Ver
    2003,2007,2010,2013
    Posts
    65

    Re: complicated Help about VBA Find/Replace

    Dear porucha,

    first of all i don't have enough words to give a big thanks to you really!

    your code seems working but not 100%, maybe it is my fault that i didn't explain it clear


    now after i used your code i found that result, it copies "#footnote-ref-3" to each paragraph on file and that is not right

    for ex: all paragraphs will have #footnote-ref- but from 1 to 1000 ----> (#footnote-ref-1, #footnote-ref-2" , #footnote-ref-3" ....etc)

    so i can't force it to copy "#footnote-ref-" for one value each time

    so i just want to copy that text that exist between "<a href=" and </a>, whatever it is #footnote-ref-1 or #footnote-ref-3 or any other number


    so i hope you got my point now, please can you can make a little adjustment

    many thanks a lot for your time and efforts

  4. #4
    Registered User
    Join Date
    01-11-2017
    Location
    London, England
    MS-Off Ver
    2003,2007,2010,2013
    Posts
    65

    Re: complicated Help about VBA Find/Replace

    please check the wanted result below for more clear explanation



    Before:

    <li id="footnote-2"><p>*am from the state of Virginia.At the close of the Civil War I found myself without a home, without money and without work. <a href="#footnote-ref-2">[1]</a></p></li>

    <li id="footnote-3"><p> also of Virginia. We were extremely lucky <a href="#footnote-ref-3">[2]</a></p></li>

    <li id="footnote-4"><p> was sure they wanted to capture Powell. <a href="#footnote-ref-4">[3]</a></p></li>

    <li id="footnote-5"><p> It was a pleasant feeling. My body became extremely heavy <a href="#footnote-ref-5">[4]</a></p></li>
    After:


    <li id="footnote-2"><p><a href="#footnote-ref-2">[1]</a>am from the state of Virginia.* At the close of the Civil War I found myself without a home, without money and without work. <a href="#footnote-ref-2">*</a></p></li>

    <li id="footnote-3"><p><a href="#footnote-ref-3">[2]</a> also of Virginia. We were extremely lucky <a href="#footnote-ref-3">*</a></p></li>

    <li id="footnote-4"><p><a href="#footnote-ref-4">[3]</a> was sure they wanted to capture Powell. <a href="#footnote-ref-4">*</a></p></li>

    <li id="footnote-5"><p><a href="#footnote-ref-5">[4]</a> It was a pleasant feeling.My body became extremely heavy <a href="#footnote-ref-5">*</a></p></li>


    Last edited by Ethen5155; 10-14-2017 at 11:47 PM.

  5. #5
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: complicated Help about VBA Find/Replace

    In Word, you can do this via a wildcard Find/Replace, where:
    Find = (\<li id="footnote-)([0-9]{1,})("\>\<p\>)(*)(\<a href="#footnote-ref-\2"\>)(\[[0-9]{1,}\])(\</a\>)
    Replace = \1\2\3\5\6\7\4\5*\7
    No macros required.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  6. #6
    Registered User
    Join Date
    01-11-2017
    Location
    London, England
    MS-Off Ver
    2003,2007,2010,2013
    Posts
    65

    Re: complicated Help about VBA Find/Replace

    Hi Paul,

    Thanks for your reply, but i found that appeared to me !!

    1.png

    any hint??

  7. #7
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: complicated Help about VBA Find/Replace

    Depending on your regional settings, you may need to replace both instances of {1,} with {1;}.

  8. #8
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,143

    Re: complicated Help about VBA Find/Replace

    Quote Originally Posted by Ethen5155 View Post
    please check the wanted result below for more clear explanation
    Before: ...
    After: ...
    Ok, I'll check it out

  9. #9
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,143

    Re: complicated Help about VBA Find/Replace

    And now will it work or not ?
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] help with a complicated find and replace
    By stephme55 in forum Excel General
    Replies: 4
    Last Post: 12-14-2015, 02:35 PM
  2. complicated find and replace
    By ammartino44 in forum Excel General
    Replies: 2
    Last Post: 08-14-2015, 03:39 PM
  3. complicated find and replace
    By ammartino44 in forum Excel General
    Replies: 5
    Last Post: 06-13-2015, 04:12 AM
  4. very complicated find and replace code
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-01-2015, 04:03 PM
  5. [SOLVED] Formula to use in complicated replace
    By njelezn in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-20-2015, 07:11 PM
  6. Complicated Find - Replace
    By abertrand in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-13-2009, 01:13 PM
  7. Userform, Find and Replace - Really Complicated
    By HelenMcKenzie in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-24-2006, 06:22 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1