Closed Thread
Results 1 to 13 of 13

How to use REGEX in word

  1. #1
    Forum Contributor
    Join Date
    06-20-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    359

    How to use REGEX in word

    Hello,

    I have the below code which replaces the invalid characters. Can anyone please help me to make a similar macro code for MICROSFT WORD?

    Please Login or Register  to view this content.
    Thank you

  2. #2
    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: How to use REGEX in word

    Word has nothing equivalent to Excel's Worksheet_Change event.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Forum Contributor
    Join Date
    06-20-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    359

    Re: How to use REGEX in word

    Thank you. Can I replace the invalid characters in word without change events using VBA?

  4. #4
    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: How to use REGEX in word

    You can use a wildcard Find/Replace.

  5. #5
    Forum Contributor
    Join Date
    06-20-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    359

    Re: How to use REGEX in word

    I don't have knowledge of MSWORD VBA. Could you please let me know how to use wildcard Find/Replace in VBA.

    I want to replace "[~`!#$%^*]" all these characters with Nullstring.

    Thank you

  6. #6
    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: How to use REGEX in word

    Try:
    Please Login or Register  to view this content.
    Last edited by macropod; 01-28-2018 at 07:10 PM.

  7. #7
    Forum Contributor
    Join Date
    06-20-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    359

    Re: How to use REGEX in word

    Thank you. It's working. How to make this macro available for all word documents and how to assign this macro to the toolbar?

  8. #8
    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: How to use REGEX in word

    To make it available to all documents, add the macro to Word's 'Normal' template. Your profile indicates you're using Office 2010, which doesn't have a toolbar. I suggest you simply create a keyboard shortcut; otherwise, to add the macro to the Quick Access Toolbar, use File|Options|Quick Access Toolbar>Choose commands from:Macros.

  9. #9
    Registered User
    Join Date
    12-20-2017
    Location
    New York
    MS-Off Ver
    2016
    Posts
    6

    Re: How to use REGEX in word

    Although the "use wildcards" option in Word's Find dialog does a lot of what RegEx does, it is not the same as RegEx.

  10. #10
    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: How to use REGEX in word

    Your point being? Sure Word's "use wildcards" option isn't a complete RegEx solution, but it does everything the OP needs and it'll also do a lot you can't do with RegEx.

  11. #11
    Registered User
    Join Date
    11-20-2023
    Location
    Houston, TX, USA
    MS-Off Ver
    18
    Posts
    2

    Re: How to use REGEX in word

    Regex in MS products is unnecessarily tedious and difficult. If you have a document where you need to replace a great deal of formatting or test, you are better off opening the document first in LibreOffice, making the replacements, then saving to MS format.
    Last edited by larrybradley; 11-20-2023 at 11:58 AM.

  12. #12
    Registered User
    Join Date
    11-20-2023
    Location
    Houston, TX, USA
    MS-Off Ver
    18
    Posts
    2

    Re: How to use REGEX in word

    Using Regex in MS Office products is unnecessarily difficult and tedious. If you have a lot of Find and Replace tasks in a large document, it is far easier to first open the document in LibreOffice and use that program's sensible and sane Regex
    functions to do your Find and Replace, then save back to MS format.

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,460

    Re: How to use REGEX in word

    Thanks, but the thread is already five and a half years old ...
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA: Find all sentences with a given word. Partial match preferred with regex.
    By first_jaguar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-26-2017, 02:26 PM
  2. RegEx Backreference
    By wwconslt in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-21-2017, 04:09 AM
  3. [SOLVED] help with a function using Regex
    By Pancho3 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-24-2016, 09:22 PM
  4. RegEx not getting expression
    By amartinez988 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-01-2015, 11:14 AM
  5. Not able to use the regex in code...
    By lifeankit in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-22-2014, 06:54 AM
  6. RegEx Problem
    By Marshall80 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-24-2011, 04:49 AM
  7. [SOLVED] RegEx to parse something like this...
    By R Avery in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-21-2005, 07:06 PM

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