![]() |
|
#1
|
||||
|
||||
![]()
Perhaps:
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, """")))) 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 Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#2
|
|||
|
|||
![]()
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 |
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
leeqiang | Excel Programming | 10 | 04-17-2022 03:30 AM |
![]() |
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 |
![]() |
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 |