View Single Post
 
Old 03-21-2022, 06:55 AM
sjohnson sjohnson is offline Windows 11 Office 2019
Novice
 
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