Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-20-2017, 03:17 PM
Tye30 Tye30 is offline Ugraded to Word 2013 Macro not performing Windows 7 32bit Ugraded to Word 2013 Macro not performing Office 2010 32bit
Novice
Ugraded to Word 2013 Macro not performing
 
Join Date: Apr 2017
Posts: 7
Tye30 is on a distinguished road
Default Ugraded to Word 2013 Macro not performing

Upgraded to Word 2013 from Word 2010 and the time to execute this macro went form 8 seconds to 208 seconds. When I run the code with not using
Code:
Application.ScreenUpdating = False
it actually runs faster at 191 seconds. Is there a setting I need to adjust or is this some kind of bug?

I am a beginner in VBA and I got this code from online



Code:
 
Dim StartTime As Double
Dim SecondsElapsed As Double
  StartTime = Timer
 
    Application.ScreenUpdating = False
 
    Dim oPara As Paragraph
    For Each oPara In ActiveDocument.Paragraphs
        If InStr(1, oPara.Range.Text, "!Z! !") = 0 Then
            oPara.Range.Delete
        End If
    Next
 
    With ActiveDocument.Range.Find
        .Replacement.ClearFormatting
        .Text = "!"
        .Replacement.Text = "|"
        .MatchWildcards = False
        .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue
    End With
 
    Application.ScreenUpdating = True
 
  SecondsElapsed = Round(Timer - StartTime, 2)
  MsgBox "This code ran successfully in " & SecondsElapsed & " seconds", vbInformation
Attached Files
File Type: docx Test_Format.docx (175.1 KB, 28 views)

Last edited by Tye30; 06-21-2017 at 06:25 AM. Reason: Add attachment
Reply With Quote
  #2  
Old 06-20-2017, 09:18 PM
gmayor's Avatar
gmayor gmayor is offline Ugraded to Word 2013 Macro not performing Windows 10 Ugraded to Word 2013 Macro not performing Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
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 ofgmayor has much to be proud of
Default

It's all relative and impossible to check without the document you are processing. On my PC (lots of memory and SSD drive) with a 20 page document it ran in just over a second, according to your timer, but it is also true to say that VBA processing in Word 2013/2016 is generally slower than it is in Word 2010
__________________
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
  #3  
Old 06-21-2017, 06:27 AM
Tye30 Tye30 is offline Ugraded to Word 2013 Macro not performing Windows 7 32bit Ugraded to Word 2013 Macro not performing Office 2010 32bit
Novice
Ugraded to Word 2013 Macro not performing
 
Join Date: Apr 2017
Posts: 7
Tye30 is on a distinguished road
Default

Thank you for replying Graham, and I have added an attachment of a modified version of the docs I use. I appreciate any help you may be able to give me!

I view these docs in Web Layout View

Last edited by Tye30; 06-21-2017 at 06:28 AM. Reason: Important Note
Reply With Quote
  #4  
Old 06-21-2017, 10:50 PM
gmayor's Avatar
gmayor gmayor is offline Ugraded to Word 2013 Macro not performing Windows 10 Ugraded to Word 2013 Macro not performing Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
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 ofgmayor has much to be proud of
Default

Using your test document, which is far more complex than I had anticipated, the process is indeed much slower than in Word 2010 and even in 2010, your test document took rather longer than 8 seconds, however while my PC may have a lot of memory and a very fast drive, it does not have a particularly fast processor.

As you are processing a lot of paragraphs sequentially, there is not a lot you can do to speed that process.

If you can eliminate many (or all) of the unwanted paragraphs using the replace function then the process would have less to do and thus be faster. 'Replace' is infinitely faster than the paragraph looping.

e.g. a wildcard search for
\! \! \!*^13
replace with nothing will remove a lot of unwanted paragraphs very quickly and the processing time of your macro was then reduced to a third.

You should be able to remove many of the others similarly, but as the document is a mock up without real values, it is difficult to suggest the wildcard strings required, however see http://www.gmayor.com/replace_using_wildcards.htm
__________________
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2013 two laptops near identical spec performing differently mobile Excel 6 04-04-2016 03:39 AM
Ugraded to Word 2013 Macro not performing Copy macro/template from Word 2013 to 365 saclucas Word VBA 1 02-18-2016 09:19 PM
Ugraded to Word 2013 Macro not performing Word 2013: Hotkey to call a macro arjfca Word 2 12-04-2014 12:53 AM
Ugraded to Word 2013 Macro not performing Macro not Performing Formula Update as Expected tandchas Excel Programming 7 06-27-2014 05:42 AM
Ugraded to Word 2013 Macro not performing Question about macro in word 2013 tombags Word 1 06-25-2014 04:56 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:40 PM.


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