Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-22-2023, 01:26 AM
RobiNew RobiNew is offline Deleting specific strings of characters in specific positions Windows 10 Deleting specific strings of characters in specific positions Office 2016
Competent Performer
Deleting specific strings of characters in specific positions
 
Join Date: Sep 2023
Posts: 200
RobiNew is on a distinguished road
Default Deleting specific strings of characters in specific positions


I devised (part of) a macro to delete certain strings of characters in specific positions. It works, but can someone suggest a more efficient way to obtain the same results? Thanks!
Code:
Sub DeleteCertainStrings()

Set oRng = ActiveDocument.StoryRanges(1)
 
With oRng.Find
.Text = "Nnnnnnnnnnnn/Nnnnnnnnn^p" '1: text to delete except ^p, which is the 1st para of the 1st page
.Execute
End With
If oRng.Find.Found = True Then
oRng.Delete
End If

With oRng.Find '2: text to delete (including final space) except ^p, the 1st para of the 2nd page
 .Text = "Nn Nnn Nnnnn. Nnnn nn NNN Nnnnnnnnn ^p"
 .Execute
End With
If oRng.Find.Found = True Then
oRng.Delete
 End If

With oRng.Find '3: to delete everything except ^p, followed by 10 ^p's, which must remain
.Text = "Nnn nnnnnnnnnn nnnnn nn nnn nnnnn nn nnnnnnnnnn^l
nnnn nnn nnnnnnnn nn Nnnnn Nnnnnnn’n “Nnnnnnn” (G3-1v).^p"
.Execute
End With
If oRng.Find.Found = True Then
oRng.Delete
 End If
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting specific strings of characters in specific positions Word macro for deleting a line that starts with a specific character + deleting the line before eduardb Word 1 08-10-2022 03:17 AM
Search Word for specific strings and replace with hyperlinks from a list jlive24 Word VBA 2 06-26-2022 08:14 PM
Extracting Specific Text Strings PWH68 Word VBA 6 10-08-2019 02:07 AM
Deleting specific strings of characters in specific positions Deleting Characters in a specific location in Word 2010 ppayaw Word VBA 8 12-13-2016 08:11 AM
Deleting specific strings of characters in specific positions update style of all strings available between two specific strings vikrantkale Word 1 03-28-2011 06:13 PM

Other Forums: Access Forums

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