View Single Post
 
Old 07-15-2017, 06:29 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

I'm not sure what one of your documents looks like when you initiate this code but why don't you take the spaces out before you ever put it in the clipboard?

Code:
Sub Macro18()
Dim oClipboard As DataObject
Dim oRng As Range
  'This part gets a person's name from a Word document to the oClipboard.
  Selection.EndKey Unit:=wdStory
  Selection.MoveUp Unit:=wdLine, Count:=4
  Selection.EndKey Unit:=wdLine, Extend:=wdExtend
  Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
  Set oRng = Selection.Range
  oRng.Text = Trim(oRng.Text)
  oRng.Copy
  Undo 1 'Put the spaces back in the text.
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote