Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-12-2024, 06:00 AM
vivka vivka is offline Deleting the first word of a second paragraph Windows 7 64bit Deleting the first word of a second paragraph Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 228
vivka is on a distinguished road
Default

This is better. Since cset recognizes characters, not strings, "Example" is useless:
Code:
Sub Del_Test()
Dim oRng As range
    Set oRng = selection.Paragraphs(2).range
    If InStr(oRng, "Example") Then
        oRng.Collapse
        oRng.MoveEndUntil cset:="E"
    Else
        oRng.Collapse
        oRng.MoveEnd unit:=wdCharacter, count:=8
    End If
    oRng.Delete
Set oRng = Nothing
End Sub

Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting all text from a slide pack without deleting the formatting redordead2389 PowerPoint 0 05-31-2023 06:50 AM
Deleting the first word of a second paragraph 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
Inserting text from a Userform into a Field in a paragraph in a paragraph in a word document storemaz Word VBA 1 03-13-2020 08:11 AM
Deleting the first word of a second paragraph Deleting paragraph commands afndst Word VBA 2 12-30-2015 02:07 AM
Deleting the first word of a second paragraph Deleting a script in an equation without deleting the whole term allankey Word 1 02-15-2014 07:09 AM

Other Forums: Access Forums

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