Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-11-2022, 09:33 AM
Mattc1978 Mattc1978 is offline run vba script in word for removing certain characters Windows 10 run vba script in word for removing certain characters Office 2019
Novice
run vba script in word for removing certain characters
 
Join Date: May 2021
Posts: 13
Mattc1978 is on a distinguished road
Question run vba script in word for removing certain characters

Ok,



Here is the challenge, I need to remove all instances of brackets, speech marks and * in a word document.

How do i string together the requests either in the CTRL H find and replace function or in VBA.

The problem arises when the information is being transferred into a word template from MS Forms.

It leaves the brackets etc in when i change the docx into doc.

I have done it as something like this \[*\] but i want to string them together to include "*" for example and few others for one button press.

I dont know how to connect them?

I am a total amateur obviously. Help
Attached Files
File Type: doc 568923055.doc (181.5 KB, 5 views)
Reply With Quote
  #2  
Old 05-11-2022, 03:41 PM
macropod's Avatar
macropod macropod is offline run vba script in word for removing certain characters Windows 10 run vba script in word for removing certain characters Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You can't put those variations all into a single Find expression. You could use a macro, however, to automate the process. For example:
Code:
Sub BulkFindReplace()
Application.ScreenUpdating = False
Dim ArrFnd As Variant, i As Long
'Array of wildcard Find expressions
ArrFnd = Array("[*\]", "[\*“”""""]")
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Format = False
  .Forward = True
  .MatchWildcards = True
  .Replacement.Text = ""
   'Process each item from ArrFnd
  For i = 1 To UBound(ArrFnd)
    .Text = ArrFnd(i)
    .Execute Replace:=wdReplaceAll
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-12-2022, 05:57 AM
Mattc1978 Mattc1978 is offline run vba script in word for removing certain characters Windows 10 run vba script in word for removing certain characters Office 2019
Novice
run vba script in word for removing certain characters
 
Join Date: May 2021
Posts: 13
Mattc1978 is on a distinguished road
Thumbs up Macro worked!!!

Hi Macropod,

Can you add change font to arial and remove these types of brackets also [ ]

Many Thanks

How would you best recommend to learn Macro?

Thanks

Matt
Reply With Quote
  #4  
Old 05-12-2022, 04:36 PM
macropod's Avatar
macropod macropod is offline run vba script in word for removing certain characters Windows 10 run vba script in word for removing certain characters Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

What purpose would be served by changing the font of something you're deleting?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 05-13-2022, 03:41 AM
Mattc1978 Mattc1978 is offline run vba script in word for removing certain characters Windows 10 run vba script in word for removing certain characters Office 2019
Novice
run vba script in word for removing certain characters
 
Join Date: May 2021
Posts: 13
Mattc1978 is on a distinguished road
Default

Hi Paul,

When the template is populated and a document is created, the document is a doc.x, I have to save as a doc. to remove the active fields. The hangover from the active fields is the brackets, speech marks, *, etc. The macro I hope will remove all of these leaving only the inputs text-wise from the eform. When the eform populates with the text it defaults to a font that can't be used for neurodiversity reasons (dyslexia) and corporate continuity. So I have to manually change to Arial using CTRL A then change to Arial. The form is the quality assured and then posted as a PDF on a tablet, for firefighters to be read as a descriptor of a premises hazards, should they attend a fire there.
If you know of a way to bulk remove empty rows and columns that haven't had input from the eform without using Kutools plus, then that would be amazing. The final bit is to remove anywhere with the word info: if there was nothing pulled through from the eform to populate that row and in turn now being blank delete said row. Many Thanks Matt
Reply With Quote
  #6  
Old 05-13-2022, 03:18 PM
macropod's Avatar
macropod macropod is offline run vba script in word for removing certain characters Windows 10 run vba script in word for removing certain characters Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

This would be much easier to resolve if we had access to the problem document. Can you attach a document to a post with some representative data (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 05-14-2022, 02:43 AM
Mattc1978 Mattc1978 is offline run vba script in word for removing certain characters Windows 10 run vba script in word for removing certain characters Office 2019
Novice
run vba script in word for removing certain characters
 
Join Date: May 2021
Posts: 13
Mattc1978 is on a distinguished road
Default

See Attached - offending document
Attached Files
File Type: docx 568923055 doc x version before conversion.docx (67.6 KB, 8 views)
File Type: docx 568923055 doc. version.docx (67.6 KB, 8 views)
Reply With Quote
  #8  
Old 05-15-2022, 06:43 PM
macropod's Avatar
macropod macropod is offline run vba script in word for removing certain characters Windows 10 run vba script in word for removing certain characters Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Neither of your two attachments contains any fields that I can see. What they contain is content controls. Saving the documents in the .doc or .pdf formats will delete the content controls, leaving only the displayed output.

Instead of trying to use a macro to change the font attributes after the event, you should apply Styles with the desired formatting beforehand (i.e. to the template upon which the document is based).

Moreover, if the brackets, etc. were made part of the content control prompt text, you wouldn't have anything to delete - they'd disappear as soon as the user input something there.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 05-17-2022, 01:34 AM
Mattc1978 Mattc1978 is offline run vba script in word for removing certain characters Windows 10 run vba script in word for removing certain characters Office 2019
Novice
run vba script in word for removing certain characters
 
Join Date: May 2021
Posts: 13
Mattc1978 is on a distinguished road
Default Almost there

Hello,

I sent two doc.x by accident. I've sent the doc. version now.

Yes the content controls are now removed which is what i want. Ok ignore the font issue, can we have a macro that does the other things in one hit?

E.g.

Remove speechmarks, * and []
Then bulk remove empty rows and columns that haven't had input from the eform without using Kutools plus, then that would be amazing. The final bit is to remove anywhere with the word info: if there was nothing pulled through from the eform to populate that row and in turn now being blank delete said row.
Attached Files
File Type: doc 568923055 doc. version.doc (181.5 KB, 7 views)
Reply With Quote
  #10  
Old 05-17-2022, 02:57 PM
macropod's Avatar
macropod macropod is offline run vba script in word for removing certain characters Windows 10 run vba script in word for removing certain characters Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Ceaning up the content is as simple as:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Format = False
  .Forward = True
  .Text = "[\[\]\*“”""""]"
  .MatchWildcards = True
  .Replacement.Text = ""
  .Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
A forum search will turn up macros for deleting empty table rows.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 05-23-2022, 04:51 AM
Mattc1978 Mattc1978 is offline run vba script in word for removing certain characters Windows 10 run vba script in word for removing certain characters Office 2019
Novice
run vba script in word for removing certain characters
 
Join Date: May 2021
Posts: 13
Mattc1978 is on a distinguished road
Default

So that worked brilliantly, well happy, but the codes i have tried for the delete empty cells returns the error 5991, cannot access the individual rows in this collection, because the table vertically merged cells.
Is there a workaround Thanks Matt
What I'd really want is if the cell only contains "info:" then delete the/ remove the cell, this is because no answer has been returned, so therefore we dont want spaces everywhere.

Thanks Again Matt
Reply With Quote
  #12  
Old 05-23-2022, 08:39 AM
macropod's Avatar
macropod macropod is offline run vba script in word for removing certain characters Windows 10 run vba script in word for removing certain characters Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try, for example:
Code:
Sub TblDemo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "Info:"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
  End With
  Do While .Find.Execute
    If .Information(wdWithInTable) = True Then
      If .Text = Trim(Split(.Cells(1).Range.Text, vbCr)(0)) Then .Rows.Delete
    End If
    .Collapse wdCollapseEnd
  Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 05-24-2022, 03:05 AM
Mattc1978 Mattc1978 is offline run vba script in word for removing certain characters Windows 10 run vba script in word for removing certain characters Office 2019
Novice
run vba script in word for removing certain characters
 
Join Date: May 2021
Posts: 13
Mattc1978 is on a distinguished road
Default

Yeah didn't work...
Reply With Quote
  #14  
Old 05-24-2022, 07:28 AM
macropod's Avatar
macropod macropod is offline run vba script in word for removing certain characters Windows 10 run vba script in word for removing certain characters Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Does for me...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #15  
Old 05-25-2022, 01:08 AM
Mattc1978 Mattc1978 is offline run vba script in word for removing certain characters Windows 10 run vba script in word for removing certain characters Office 2019
Novice
run vba script in word for removing certain characters
 
Join Date: May 2021
Posts: 13
Mattc1978 is on a distinguished road
Default

It worked on the document I attached?

Thanks Matt
Reply With Quote
Reply

Tags
ctrlh, dunce, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
run vba script in word for removing certain characters Visual basic Word Script To Remove Specific Areas of a Word Doc mackied Word VBA 9 07-30-2017 03:10 PM
run vba script in word for removing certain characters Removing characters from a cell tonydoneese Excel 4 01-12-2016 07:41 AM
Strange Characters appear when selecting SHOW ALL NON PRINTING CHARACTERS ann Amber Word 1 08-01-2015 08:06 PM
Junk characters (box-like characters) in Word file Sashikala Word 1 04-20-2010 02:03 PM
Removing data between two characters Voodoo Child Excel 1 11-26-2009 01:39 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:36 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft