Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-17-2022, 08:47 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 Code to modify text when pasting

I am trying to figure out how to create two different code that modifies text that I have copied. As background, the copied text will always have this format:

"This is the text" Citation

Now sometimes there will be other quotation marks within the outer quotation marks. For instance: "This is "the" text" Citation

There will be different character spacing between the closing quotation mark and the citation. Sometimes, it will be paragraph symbols, other times braking spaces, other times only one space, etc.

For the first code, I am trying to do a few things:
  1. Paste the copied material into Word using merge formatting.
  2. Modify the beginning and ending quotation marks to be smart quotes.
  3. Make sure that after the closing quotation mark, there are two spaces between that and the citation.
  4. Get rid of any quotation marks, brackets, ellipses within the material in the parentheses.
  5. If there were quotation marks removed, add (quotation marks removed) after the citation
  6. If there were brackets, ellipses, etc. removed, add (alterations removed) after the citation. Thus, if there were both quotation marks and parentheses removed, add (quotation marks and alteration removed) after the citation.
  7. Move the cursor to the end of what I just pasted (just like what the normal paste function does).

For the second code, I am trying do everything that the first code does, but just flip how it all fits together, i.e., Citation ("This is the text").

I have a starting code, but I am having a lot of difficulties figuring out how to do the more specific things in this code. For the second code, I can't even figure out how to get it to paste correctly.

Code 1:
Code:
 Sub Cite1()
Application.ScreenUpdating = False
Dim Rng As range
Set Rng = Selection.range
Rng.PasteAndFormat (wdFormatSurroundingFormattingWithEmphasis)
With Rng
  .MoveStartUntil Chr(11), wdForward
  .End = .Start + 2
  .Text = "  "
End With
  Selection.MoveStartUntil ")", wdForward
Application.ScreenUpdating = True
End Sub
Code 2:
Code:
Sub Cite2()
Application.ScreenUpdating = False
Dim RngA As range, RngB As range, StrTmp As String
Set RngA = Selection.range
With RngA
  .Paste
  Do While .Characters.Last Like "[ " & Chr(11) & vbCr & "]"
    .End = .End - 1
  Loop
  .InsertBefore " (" & Chr(147)
  Set RngB = .Duplicate
  With RngB
    .MoveStartUntil Chr(11), wdForward
    .End = .Start + 2
    .Text = "." & Chr(148) & ") "
    .Collapse wdCollapseEnd
    .End = RngA.End
  End With
  .Collapse wdCollapseStart
  .FormattedText = RngB.FormattedText
  RngB.Text = vbNullString
End With
Application.ScreenUpdating = True
End Sub

Reply With Quote
 



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 02:54 AM.


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