Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-02-2018, 03:40 AM
Seatonian Seatonian is offline Macros from this Forum will not run. Windows 7 64bit Macros from this Forum will not run. Office 2010 64bit
Novice
Macros from this Forum will not run.
 
Join Date: Sep 2018
Posts: 7
Seatonian is on a distinguished road
Default Macros from this Forum will not run.

Hello, first time on this Forum. Have copied Macro by esteemed G Mayor from Thread 40477 (remove underscores ... ) and assigned a Key. The Macro is correctly stored in Normal template. On "running", no sign of life: compiles but does not function, does not generate Errors. Have tried the other macros in the same thread with same result. Finally, have deleted the Sub and RETYPED the desired macro from a printout. Still no activity.



One unlikely cause: I do not need the remaining components of Office. I only use Word 2010 (x84) and have not installed them. (Too complicated at my advanced age.) But G Mayor's impeccable code contains only conventional Word commands, so why will his elegant Macro not run?

What should I do? All suggestions gratefully received. Thank you.
Reply With Quote
  #2  
Old 10-02-2018, 04:12 AM
gmaxey gmaxey is offline Macros from this Forum will not run. Windows 7 32bit Macros from this Forum will not run. Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Is it actually running? I don't know what code you are talking about (why didn't you post it?), but try adding a new line just before the End Sub line i.e.,:

Msgbox "I just ran"
End Sub

When you try to run the code, do you see that message?

Yes, the code is running.

No, perhaps you have macros disabled.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 10-02-2018, 06:19 AM
Seatonian Seatonian is offline Macros from this Forum will not run. Windows 7 64bit Macros from this Forum will not run. Office 2010 64bit
Novice
Macros from this Forum will not run.
 
Join Date: Sep 2018
Posts: 7
Seatonian is on a distinguished road
Default Micros from this Forum will not run.

Thank you for your prompt reply. I have inserted the MsgBox as advised, but the Message does not appear. Macros are not disabled on my system as far as I can tell. I recall the warning about "dangerous code" being run with that setting. I did not post the Macro because I am struggling with an unfamiliar and complex Forum structure and couldn't see how to do it.



Sub Delete_Underscores()
'
' Delete_Underscores Macro
' Will delete all underscores in Document except in Mail addresses (& hyperlinks ??)
' Author = GMayor.

' This version RETYPED from published Macro because of difficulties with MS Office site.
' CALL with ALT + U (for Underscore)

Dim oRng As range
Dim oWord As range

Set oRng = ActiveDocument.range
With oRng.Find
Do While .Execute(FindText:="_")
Set oWord = oRng.Duplicate
If oWord.Words(1).Start <> ActiveDocument.range.Start Then
oWord.MoveStartUntil Chr(32), wdBackward
oWord.MoveEndUntil Chr(32) & Chr(13)
If InStr(1, oWord.Text, "@") = 0 Then oRng.Text = " "
End If
oRng.Collapse 0
Loop
End With
lbl_Exit:
Set oRng = Nothing
Set oWord = Nothing
Exit Sub

MsgBox "Yes, it ran." 'Added.

End Sub


_________________


No, I'm afraid it didn't run.


Thanks once again.
Reply With Quote
  #4  
Old 10-02-2018, 12:07 PM
gmaxey gmaxey is offline Macros from this Forum will not run. Windows 7 32bit Macros from this Forum will not run. Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Ok, open your VBA editor again, put the cursor in the code and click the "F8" key to step through the macro line by line. After the first loop, you can click the Run button "F5"

Does the macro run? Yes, there is nothing wrong with the macro. Perhaps you have not properly set your shortcut key.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 10-02-2018, 03:40 PM
Seatonian Seatonian is offline Macros from this Forum will not run. Windows 7 64bit Macros from this Forum will not run. Office 2010 64bit
Novice
Macros from this Forum will not run.
 
Join Date: Sep 2018
Posts: 7
Seatonian is on a distinguished road
Default

Thank you Greg for your suggestions. I have used F8 and F5 as you suggest. No, still no sign of movement, no errors, no effect on the TestBed text. Yet, there is a cursor flashing in the Code, and the Stepping process operates without incident (but finds no errors because there aren't any.)
When I was typing the Code I made a few unnoticed typo errors. These were detected by the Compiler and corrected, proving that the Compiler was working.

Yes, my first thought was the Keybinding but it is quite sound. I used several Key Combinations, and I also tried running the Code from a QAT button, also without success.

I know nothing about References, but I ask myself whether any essential Reference, which is part of the Office Suite and therefore NOT present on my version of Word, could be responsible.

I confirm that the Macro Security button in Developer reveals that all Macros are enabled (and warns of the danger ...).
More generally, I have many Macros all of which work correctly at present - except this one.
However, I was poking about in the VBE a few days before Copying the Macro in question and may have accidentely changed some setting. Thank you for your continued interest.
Reply With Quote
  #6  
Old 10-02-2018, 03:58 PM
jeffreybrown jeffreybrown is offline Macros from this Forum will not run. Windows Vista Macros from this Forum will not run. Office 2007
Expert
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Not sure if it will help you or not, but I used the code from post #3 and it runs fine.

Also, the msgbox you added will never run as you have placed it directly after Exit Sub.

This
Code:
MsgBox "Yes, it ran." 'Added.
Exit Sub
End Sub

Not This

Code:
Exit Sub
MsgBox "Yes, it ran." 'Added.
End Sub
But even with this, not sure why you even need Exit Sub as there is nothing left to do or skip.
Reply With Quote
  #7  
Old 10-02-2018, 09:29 PM
macropod's Avatar
macropod macropod is offline Macros from this Forum will not run. Windows 7 64bit Macros from this Forum will not run. Office 2010 32bit
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 this run:
Code:
Sub Test()
MsgBox "!"
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 10-02-2018, 09:43 PM
gmayor's Avatar
gmayor gmayor is offline Macros from this Forum will not run. Windows 10 Macros from this Forum will not run. Office 2016
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

I have again tested the code (repeated below) and it does what it is supposed to do and the completion message (not part of the original) works where it is now placed.

If the macro doesn't do anything, it is likely to be that the criteria set in the code does not match what is in the document. Post a sample document in which it does not work.

Quote:
Originally Posted by jeffreybrown View Post
not sure why you even need Exit Sub as there is nothing left to do or skip.
It's a personal programming foible, that I use will all my code, and which is primarily used in conjunction with error handling routines, though in this instance there is no such routine.
Code:
Sub Delete_Underscores()
' 'Graham Mayor - http://www.gmayor.com - Last updated - 03 Oct 2018
'
' Delete_Underscores Macro
' Will delete all underscores in Document except in Mail addresses (& hyperlinks ??)
' This version RETYPED from published Macro because of difficulties with MS Office site.
' CALL with ALT + U (for Underscore)

Dim oRng As Range
Dim oWord As Range

    Set oRng = ActiveDocument.Range
    With oRng.Find
        Do While .Execute(FindText:="_")
            Set oWord = oRng.Duplicate
            If oWord.Words(1).Start <> ActiveDocument.Range.Start Then
                oWord.MoveStartUntil Chr(32), wdBackward
                oWord.MoveEndUntil Chr(32) & Chr(13)
                If InStr(1, oWord.Text, "@") = 0 Then oRng.Text = " "
            End If
            oRng.Collapse 0
        Loop
    End With
    MsgBox "Yes, it ran."    'Added.
lbl_Exit:
    Set oRng = Nothing
    Set oWord = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #9  
Old 10-02-2018, 09:47 PM
macropod's Avatar
macropod macropod is offline Macros from this Forum will not run. Windows 7 64bit Macros from this Forum will not run. Office 2010 32bit
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

Quote:
Originally Posted by gmayor View Post
If the macro doesn't do anything, it is likely to be that the criteria set in the code does not match what is in the document. Post a sample document in which it does not work.
Or maybe macro support hasn't been installed...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 10-03-2018, 12:28 AM
gmayor's Avatar
gmayor gmayor is offline Macros from this Forum will not run. Windows 10 Macros from this Forum will not run. Office 2016
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

Quote:
Originally Posted by macropod View Post
Or maybe macro support hasn't been installed...
Or that
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #11  
Old 10-03-2018, 03:19 AM
Seatonian Seatonian is offline Macros from this Forum will not run. Windows 7 64bit Macros from this Forum will not run. Office 2010 64bit
Novice
Macros from this Forum will not run.
 
Join Date: Sep 2018
Posts: 7
Seatonian is on a distinguished road
Default

My thanks to contributors Jeffrey Brown, Macropod and Graham Mayor, luminaries all from across the world.

Moving the Msg Box higher in the Code has enabled it to work (and Macropod's MsgBox "!" also works.) But this is during compilation. There is still no activity (i.e. deletions) on the TestBed Text a copy of which is attached below. It deliberately has no Title.

The TestBed is just random text which, for this Project, has had Underscoring Formatting of graded complexity added. I use many macros now as I am unable to use the mouse with any accuracy. Please note that coloured or "weighted" Underscoring are not displayed within this Forum. Nor is Double Underscoring.

I am not sure what is meant by "Macro Support". And since all other macros work properly, does that not answer the question of whether it is installed? Please tell me where I can check this and when it is invoked. Thank you all for your kind contributions.



TEST.

On the Insert tab, the galleries include items that are designed to coordinate with the overall look of your document. When you create pictures, charts, or diagrams, they also coordinate with your current document look. You can easily change the formatting of selected text in the document text by choosing a look for the selected text from the Quick Styles gallery on the Home tab. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other document building blocks.You can easily change the formatting of selected text in the documenttext by choosing a look for the selected text from the Quick Styles gallery on the Home tab.
END OF TEST.




Reply With Quote
  #12  
Old 10-03-2018, 04:08 AM
gmayor's Avatar
gmayor gmayor is offline Macros from this Forum will not run. Windows 10 Macros from this Forum will not run. Office 2016
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

Your original message said that you wanted to remove underscores. Your example text displays underLINES and not underscores, which explains why nothing happens.
Try the following
Code:
Sub Delete_Underlines()
' 'Graham Mayor - http://www.gmayor.com - Last updated - 03 Oct 2018
'
' Delete_Underlines Macro
' Will delete all underlines in Document except in Mail addresses (& hyperlinks ??)

Dim oRng As Range
Dim oWord As Range
    Set oRng = ActiveDocument.Range
    With oRng.Find
        .ClearFormatting
        .Font.Underline = wdUnderlineSingle
        .Replacement.ClearFormatting
        Do While .Execute()
            If oRng.Hyperlinks.Count = 0 Then
                oRng.Font.Underline = wdUnderlineNone
                oRng.Collapse 0
            End If
        Loop
    End With
lbl_Exit:
    Set oRng = Nothing
    Set oWord = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #13  
Old 10-03-2018, 04:08 AM
jeffreybrown jeffreybrown is offline Macros from this Forum will not run. Windows Vista Macros from this Forum will not run. Office 2007
Expert
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Hi Graham,

Quote:
It's a personal programming foible, that I use will all my code, and which is primarily used in conjunction with error handling routines, though in this instance there is no such routine.
I surely wasn't intending to say it shouldn't be there, just pointing out I didn't understand it's use. Please accept my apology if it came across as a jab, because it wasn't.
Reply With Quote
  #14  
Old 10-03-2018, 04:10 AM
gmayor's Avatar
gmayor gmayor is offline Macros from this Forum will not run. Windows 10 Macros from this Forum will not run. Office 2016
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

No offence taken to apologise for. I just felt an explanation was warranted in view of the comment.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #15  
Old 10-03-2018, 08:18 AM
Seatonian Seatonian is offline Macros from this Forum will not run. Windows 7 64bit Macros from this Forum will not run. Office 2010 64bit
Novice
Macros from this Forum will not run.
 
Join Date: Sep 2018
Posts: 7
Seatonian is on a distinguished road
Default

Hello Graham,

Your new Macro works beautifully. Many thanks for finding the eventual cause of the problem. It's called Linguistic Incompetence because I thought "Underscore" was the US equivalent of the usual UK term of "Underline". I chose to use "Underscore" out of courtesy for your US usage and because you had used it in the original Macro. Sorry ! I am utterly discombobulated.

Having spent a lot of time (mine, yours and others'), may I ask your help in adding the few modifications which I had in mind at the outset but which were sidetracked somewhat. They would take me a long time by trial and error. Thank you.

1. Could it be modified so that the Cursor stops in turn at each isolated underlined word, or longer underlined phrase, and offers a choice YES / NO as to whether the Underline should be deleted?
2. I need the Code to work on a Selection to indicate the scope to be covered because I will never apply it to a whole document.
3. It would be helpful to include the deletion of Double Underline too.

Thank you and all contributors for your kindness. Renewed apologies. Good afternoon.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a sub-Forum for Office for Mac? IvanH Office 1 02-20-2014 11:31 PM
Macros from this Forum will not run. MS Windows forum? Joan64 Office 2 07-01-2013 10:18 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:27 PM.


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