Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 03-21-2022, 06:55 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

Thank you so much for the starting point! So the code is failing at the "StrRef" stage and I can't figure out why.

I made a few modifications so that if I can figure out what is wrong with the "StrRef" stage it will do most of what I want it to do. I am having trouble figuring out the right way to add in an if statement to only add in (quotations marks and alterations omitted) if those characters are actually omitted. Also, did I add in the past and format function correct?

Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Word.range, StrTxt As String, StrRef As String, StrCite As String
Set Rng = Selection.range
With Rng
  StrTxt = Trim(.Text)
  StrRef = Trim(Split(StrTxt, """")(UBound(Split(StrTxt, """"))))
  StrRef = Replace(StrRef, "[", "")
  StrRef = Replace(StrRef, "]", "")
  StrRef = Replace(StrRef, ". . .", "")
  StrRef = Replace(StrRef, "...", "")
  StrCite = Trim(Left(StrTxt, Len(StrTxt) - Len(StrRef)))
  StrCite = "(" & Chr(147) & Mid(StrCite, 2, Len(StrCite) - 2) & Chr(148) & ")"
End With
Selection.Text = StrRef & "  " & StrCite & "(quoations marks and alterations removed)"
PasteAndFormat (wdFormatSurroundingFormattingWithEmphasis)
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 09:43 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