Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-21-2018, 01:06 PM
Cosmo Cosmo is offline Range won't delete on some computers Windows Vista Range won't delete on some computers Office 2007
Competent Performer
Range won't delete on some computers
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default Range won't delete on some computers

I have a function which, among other things, removes extra spaces from the end of all paragraphs. It works properly, except on some machines it goes into an endless loop. I found out that it's not deleting a range.



My code loops WHILE the last character is a space. If there are multiple spaces at the end of a paragraph, it happily deletes all of them except for the last one it encounters, and then it continues to loop since the last character will always be a space.

I partially solved the problem by counting the # of spaces at the end, then deleting that range; it doesn't delete the last space, but it doesn't run into an endless loop.

The computers that seem to have the problem I believe all are running Windows 10 and Office 365. I think there are some which have the same setup but do work, but I'm not positive.

Here's the code that's causing the problem
Code:
        For Each oPara In oDoc.Paragraphs
            Set oRng = oPara.Range
            Set orng2 = oPara.Range
            Call oRng.MoveEnd(Unit:=wdCharacter, Count:=-1)
                While (Right(oRng.Text, 1) = " ")
                    orng2.Start = oRng.Start
                    orng2.End = oRng.End
                    Call orng2.Collapse(wdCollapseEnd)
                    Call orng2.MoveStart(Unit:=wdCharacter, Count:=-1)
                    If (Len(orng2.Text) > 0) Then
                        orng2.delete ' This FAILS on some machines!
                    End If
                Wend
        Next oPara
EDIT: I forgot that the original computer that was having this problem was running Windows 8, so it's not a Windows 10 issue. The only common denominator that I can find is that it only happened with Office 365. Most of the computers with the same specs as the first one didn't exhibit this issue.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Range won't delete on some computers Name a Range in a Word Document and then copy that range to the end of the doc w button click DanNatCorning Word VBA 1 04-29-2016 10:47 PM
Find and Delete Rows based on a range damaniam Excel Programming 2 03-12-2014 06:06 AM
Range won't delete on some computers Delete Range After Bookmark? VBA_Elfe Word VBA 3 04-05-2013 05:05 AM
Range won't delete on some computers Word VBA: Cannot Edit Range (Delete characters except the first in a table cell) tinfanide Word VBA 3 04-27-2012 09:48 AM
Can't delete range - error 5904 expatriate Word VBA 1 06-03-2011 12:12 AM

Other Forums: Access Forums

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