+ Reply to Thread
Results 1 to 14 of 14

VBScript.RegExp

  1. #1
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    VBScript.RegExp

    a week ago I asked an Excel programming question related to searching for a particular string. Leith Ross provided a solution based on RegExp. I am trying to use this method now for a PowerPoint macro.

    I used a PowerPoint macro that I use to remove carriage returns from a textbox and merged in the RegExp code. The result can be seen below.

    With this sub I am getting an Object required error message for the replace statement. I have no idea how to code this part correctly. Does anybody know how to debug this line.

    Please Login or Register  to view this content.
    Last edited by dschmitt; 06-23-2010 at 08:47 PM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: VBScript.RegExp related question

    What code did Leith provide you with? RegExp Replace is different from the other Replace, and your syntax is not right. Typically, RegExp looks something like this, in which the text pattern, if found, is replaced with nothing.

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: VBScript.RegExp related question

    Leith gave me the code below. I was looking for a code that could find a matching pair according to some criteria.

    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: VBScript.RegExp related question

    The question is how do I rewrite the replace code (in Stephen's code above) to account for a .Text (text box) instead of a Range. If I boil it down, this is the question that I have.
    Last edited by dschmitt; 06-23-2010 at 06:15 AM.

  5. #5
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: VBScript.RegExp related question

    Have you tried replacing the range reference with
    Please Login or Register  to view this content.
    ?

  6. #6
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: VBScript.RegExp related question

    I don't understand what you suggest.

    Please Login or Register  to view this content.
    ?
    Last edited by dschmitt; 06-23-2010 at 07:12 AM.

  7. #7
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: VBScript.RegExp related question

    Please Login or Register  to view this content.

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,991

    Re: VBScript.RegExp related question

    You need:
    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  9. #9
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: VBScript.RegExp related question

    Mmm, I will try that tomorrow. I am already back home. Thanks.

  10. #10
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: VBScript.RegExp related question

    Stephen, thanks, your code works perfect.

    romperstomper, your code works if used in the the below code. It doesn't work when used in Stephen's code. The below code replaces only the first found string, whereas Stephen's code replaces all strings in otxt.

    Please Login or Register  to view this content.
    Below is the full solution:

    Please Login or Register  to view this content.

  11. #11
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: VBScript.RegExp

    Glad it worked. In fact romperstomper's code is the same as mine, except that we used different With formulations. If that were taken into account his code would do exactly the same.

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,991

    Re: VBScript.RegExp

    It's the
    Please Login or Register  to view this content.
    bit that is key. I thought that was present in the original code.

  13. #13
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: VBScript.RegExp

    Oops, I hadn't even spotted that. Thanks romperstomper.

    Global=True=find all matches; Global=False=look for first match only.

  14. #14
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: VBScript.RegExp

    romperstomper. Thanks again for your solution. It works in Word too.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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