Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-20-2021, 04:50 PM
LittleScribbler LittleScribbler is offline macro problems Windows 10 macro problems Office 2013
Novice
macro problems
 
Join Date: Mar 2021
Posts: 7
LittleScribbler is on a distinguished road
Default macro problems



I found a macro and copied it into the VBA macro part of microsoft word. It highlighed the telling words in my manuscript well. When I tried to edit the macro by adding more telling words, using the same syntax, it wouldn't work. I had to replace to original to make it work. I copied and pasted a second macro and it highlighted all my vague words well, but when I wanted to use the macro for telling words again, it wasn't there. I saved both macros under all active templates and documents and the normal template as the instructions on the web sites and you tube sites suggested. I want to create other macros based on the one that works and save them so they are available every time I need them. I'm very new to macros and need to learn as much as I can. I'll be eternally grateful to anyone who can help. Thank you.
LittleScribbler
Reply With Quote
  #2  
Old 03-20-2021, 09:52 PM
gmayor's Avatar
gmayor gmayor is offline macro problems Windows 10 macro problems Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If you don't post the code and the modifications you have tried to make to it, how can we advise how to correct it?
In the meantime the table replacement options of
https://www.gmayor.com/document_batch_processes.htm
will undoubtedly do what you require.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com

Last edited by gmayor; 03-21-2021 at 03:45 AM.
Reply With Quote
  #3  
Old 03-24-2021, 04:41 PM
LittleScribbler LittleScribbler is offline macro problems Windows 10 macro problems Office 2013
Novice
macro problems
 
Join Date: Mar 2021
Posts: 7
LittleScribbler is on a distinguished road
Default

Hi
Thank you Graham for the suggestion. Here is the macro I adapted from one off the internet. It still doesn't work. The only changes I made was the name of the macro and the words I added. I do hope you, or one of the group can tell me where I've gone wrong. I want to run this macro in word documents.
LittleScribbler
Code:
Sub FillerWords()
' Highlights filler words
'
'
Dim range As range
Dim i As Long
Dim TargetList
TargetList = Array("admit", "all off", "as being", "as to whether", "as yet", "care about", "go on", "grateful every day", "if you need to", "if you want", "if you wish", "if you would like to", "I might add", "in terms of", "in my opinion", "in spite of that fact that", "in the event of", "in the event that", "in the process of", “it seems like”, “made it to”, “pick out”, “pick up on”, “play up”, “point out”, “put off”, “put together”, “really”, “spend”, “take action to”, “takes up”, “taking up”, “talk about”, “the most important thing is to”, “the reason”, “time and again”, “took up”, “try to figure out”, “went back over”, “when it comes to”, “which is”, “who is”, “will be different”, “you can”, “you’re going to”, “you’re going to have”, “you’re going to need to”, “in general”, “mostly”, “sort of”, “virtually”, “often”, “I think”, “absolutely”, “definitely”, “very”, “totally”, “literally”, “just”, “ironically”, “truly”, “actually”, “basically”, “to know”, “I see”, “I feel”, “I hear”, “I can feel”, “almost”, “all of”, “factor”, “for all intents and purposes”, “for the most part”, “for the purpose of”, “harder than it has to be”, “individual”, “initial”, “on a regular basis”, “the first step is to”, “time and time again”, “with reference to”)
For i = 0 To UBound(TargetList)
  Set range = ActiveDocument.range
    With range.Find
      .Text = TargetList(i)
      .Format = True
      .MatchCase = False
      .MatchWholeWord = True
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      Do While .Execute(Forward:=True) = True
        range.HighlightColorIndex = wdPink
      Loop
    End With
  Next
End Sub

Last edited by macropod; 03-24-2021 at 06:04 PM. Reason: Added code tags & formatting
Reply With Quote
  #4  
Old 03-24-2021, 06:14 PM
macropod's Avatar
macropod macropod is offline macro problems Windows 10 macro problems Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

There are multiple problems with your code, above all, the liberal use of smart quotes in the array. The structure is also poor. Try:
Code:
Sub FillerWords()
Application.ScreenUpdating = False
Dim i As Long, h As Long, TargetList
h = Options.DefaultHighlightColorIndex: Options.DefaultHighlightColorIndex = wdPink
TargetList = Array("admit", "all off", "as being", "as to whether", "as yet", "care about", "go on", _
  "grateful every day", "if you need to", "if you want", "if you wish", "if you would like to", _
  "I might add", "in terms of", "in my opinion", "in spite of that fact that", "in the event of", _
  "in the event that", "in the process of", "it seems like", "made it to", "pick out", "pick up on", _
  "play up", "point out", "put off", "put together", "really", "spend", "take action to", "takes up", _
  "taking up", "talk about", "the most important thing is to", "the reason", "time and again", "took up", _
  "try to figure out", "went back over", "when it comes to", "which is", "who is", "will be different", _
  "you can", "you’re going to", "you’re going to have", "you’re going to need to", "in general", "mostly", _
  "sort of", "virtually", "often", "I think", "absolutely", "definitely", "very", "totally", "literally", _
  "just", "ironically", "truly", "actually", "basically", "to know", "I see", "I feel", "I hear", _
  "I can feel", "almost", "all of", "factor", "for all intents and purposes", "for the most part", _
  "for the purpose of", "harder than it has to be", "individual", "initial", "on a regular basis", _
  "the first step is to", "time and time again", "with reference to")
With ActiveDocument.Content.Find
  .Format = False
  .MatchCase = False
  .MatchWholeWord = True
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  .Replacement.Text = "^&"
  .Replacement.Highlight = True
  For i = 0 To UBound(TargetList)
    .Text = TargetList(i)
    .Execute Replace:=wdReplaceAll
  Next
End With
Options.DefaultHighlightColorIndex = h
Application.ScreenUpdating = True
End Sub
PS: When posting code, please structure your code and use the code tags, indicated by the # button on the posting menu. Without the code tags, your posted code loses much of whatever structure it had.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 03-24-2021, 07:02 PM
Guessed's Avatar
Guessed Guessed is offline macro problems Windows 10 macro problems Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Along with Paul's corrections, I would also expect problems with a single line of VBA growing beyond limits. You can reduce the likelihood of that being an issue by simplifying the quote marks and concatenating chunks into separate lines.
Code:
Sub FillerWords()
  ' Highlights filler words
  Dim i As Long, sList As String, TargetList() As String
  sList = "admit|all off|as being|as to whether|as yet|care about|go on|grateful every day|if you need to|"
  sList = sList & "if you want|if you wish|if you would like to|I might add|in terms of|in my opinion|"
  sList = sList & "in spite of that fact that|in the event of|in the event that|in the process of|it seems like|"
  sList = sList & "made it to|pick out|pick up on|play up|point out|put off|put together|really|spend|take action to|"
  sList = sList & "takes up|taking up|talk about|the most important thing is to|the reason|time and again|took up|"
  sList = sList & "try to figure out|went back over|when it comes to|which is|who is|will be different|you can|"
  sList = sList & "you're going to|you're going to have|you're going to need to|in general|mostly|sort of|virtually|"
  sList = sList & "often|I think|absolutely|definitely|very|totally|literally|just|ironically|truly|actually|basically|"
  sList = sList & "to know|I see|I feel|I hear|I can feel|almost|all of|factor|for all intents and purposes|for the most part|"
  sList = sList & "for the purpose of|harder than it has to be|individual|initial|on a regular basis|the first step is to|time and time again|with reference to"
  
  TargetList = Split(sList, "|")
  
  Options.DefaultHighlightColorIndex = wdPink
  With ActiveDocument.Content.Find
    .MatchCase = False
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Wrap = wdFindContinue
    .ClearFormatting
    .Replacement.ClearFormatting
    .Replacement.Highlight = True
    For i = LBound(TargetList) To UBound(TargetList)
      .Text = TargetList(i)
      .Execute Replace:=wdReplaceAll
    Next
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Last edited by Guessed; 03-24-2021 at 09:15 PM. Reason: Fixed spelling mistake 'simplying'
Reply With Quote
  #6  
Old 03-24-2021, 07:38 PM
macropod's Avatar
macropod macropod is offline macro problems Windows 10 macro problems Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Quote:
Originally Posted by Guessed View Post
Along with Paul's corrections, I would also expect problems with a single line of VBA growing beyond limits. You can reduce the likelihood of that being an issue by simplying the quote marks and concatenating chunks into separate lines.
True, but that isn't an issue with the OP's code warranting such an approach.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 03-24-2021, 09:12 PM
Guessed's Avatar
Guessed Guessed is offline macro problems Windows 10 macro problems Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You may be right but I read the initial post as saying that was exactly the problem...
Quote:
When I tried to edit the macro by adding more telling words, using the same syntax, it wouldn't work
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #8  
Old 03-24-2021, 09:42 PM
macropod's Avatar
macropod macropod is offline macro problems Windows 10 macro problems Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

I'd suggest that was because those "more telling words" were bounded by smart quotes instead of plain quotes. Everything after "in the process of" was bounded by smart quotes.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 03-26-2021, 11:40 PM
LittleScribbler LittleScribbler is offline macro problems Windows 10 macro problems Office 2013
Novice
macro problems
 
Join Date: Mar 2021
Posts: 7
LittleScribbler is on a distinguished road
Default

Hi
Thank you everyone who has helped me with this macro problem.

I haven't learnt batch files yet, but would love to Graham

The rewritten macros from macropod, Paul Edstein and Guessed worked. Thank you so much. I'm delighted.

For macropod and Paul Edstein, I didn't know what smart quotes were, but think I might now after reading all the feedbacks again. I still don't know what poor structure, stucture code or code tags are. I can see the hash mark at the top now and never knew what it was for, but I'll press it before I sent this message and hope the message still gets through.

For guessed, is there a limit to the amount of words I can use in a macro?

LittleScribbler
Reply With Quote
  #10  
Old 03-27-2021, 06:21 AM
macropod's Avatar
macropod macropod is offline macro problems Windows 10 macro problems Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Quote:
Originally Posted by LittleScribbler View Post
is there a limit to the amount of words I can use in a macro?
There is a limit of 64K characters on the size of a code module. And a given expression can have at most 24 continuations (i.e. line breaks the '_' at the end). My code used only 12, but if for some reason I was running up against the 24 continuation limit, I could simply have made each line longer. Conversely, notwithstanding the 64K code module limit, VBA can also handle strings up to 2GB in length.

Lots of VBA functions have their own limits, though. Hence Find/Replace has a 255-character limit for each expression.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro problems Footnote extraction macro [Why is this macro so slow? / anyway to make it faster?] Le_Blanc Word VBA 10 03-22-2021 11:38 AM
Problems with Macro for inserting autotext when autotext name isn't followed by a space amz1950 Word VBA 0 02-14-2018 10:20 AM
Macro problems with Word for Mac 2016 16.9.1 JML Word VBA 2 02-03-2018 01:14 PM
Spell check macro within macro button field doesn't work in one document samuelle Word VBA 0 07-20-2016 02:27 AM
Cutting and Pasting and Macro problems in Excel 2010 enkel Excel Programming 3 01-02-2012 10:15 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:01 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