Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-23-2022, 08:25 AM
sjohnson sjohnson is offline Code to modify text when pasting Windows 11 Code to modify text when pasting Office 2019
Novice
Code to modify text when pasting
 
Join Date: Mar 2022
Posts: 4
sjohnson is on a distinguished road
Default


This code is amazing! I cannot thank you enough for the help! I made a few modifications so that it will paste in the information instead of just change the format of selected text. I also attached a modified example to show what I was trying to do for the second code (this is example 3). I had a few questions. First, what am I doing incorrectly in my modification to move the cursor to the end of what I just pasted in? Second, how can I add in an the quotation marks omitted and alterations removed? Third, when I modified the code to paste in items, it changes everything in the paragraph, not just the pasted in items (meaning if the previous already existed sentence has a bracket, it removes that bracket after it pastes in the new stuff). Currently, the modified code 1 is:

Code:
Sub Demo1()
Application.ScreenUpdating = False
Set Rng = Selection.range
Rng.PasteAndFormat (wdFormatSurroundingFormattingWithEmphasis)
With Selection.Paragraphs.First.range.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Format = False
    .Forward = True
    .Wrap = wdFindStop
    .MatchWildcards = True
    .Text = "[“”\(\[\)\]]"
    .Replacement.Text = ""
    .Execute Replace:=wdReplaceAll
    .Text = Chr(34)
    .Replacement.Text = """"
    .Execute Replace:=wdReplaceAll
    .Text = ". . ."
    .Replacement.Text = "…"
    .Execute Replace:=wdReplaceAll
    .Text = "^s"
    .Replacement.Text = " "
    .Execute Replace:=wdReplaceAll
    .Text = "[ ]{2,}"
    .Replacement.Text = " "
    .Execute Replace:=wdReplaceAll
    .Text = "[^l^13]{1,}"
    .Replacement.Text = "  "
    .Execute Replace:=wdReplaceAll
End With
Selection.Move wdCharacter, Len(Rng)
Application.ScreenUpdating = True
End Sub
To add in the quotation marks and alterations removed, I know I need to do some type of if statement that converts the Rng to a string and then checks the string and then does an if statement, but I can't quite figure out all of this yet (sorry, I am still learning Word VBA).
Attached Files
File Type: docx Example.docx (17.8 KB, 8 views)
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to modify text when pasting How to modify the code to meet the corresponding requirements leeqiang Excel Programming 10 04-17-2022 03:30 AM
Code to modify text when pasting how modify a macro code tarikov2006 Excel Programming 1 11-18-2016 04:10 AM
Modify right-click context menu to only allow pasting text derajlance Word VBA 0 05-24-2016 02:25 PM
Code to modify text when pasting Recovering/Removing a Password to Modify PPAM Code Steve_B PowerPoint 3 01-08-2014 01:06 PM
Modify vba code to print based on name in the InputBox OTPM Project 0 05-25-2011 02:03 AM

Other Forums: Access Forums

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