View Single Post
 
Old 06-21-2023, 10:36 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Try this code
Code:
Option Explicit

Const sSS As String = "StyleSheet.docx"

Sub Send2StyleSheet()
  Dim sPath As String, docSS As Document, aRng As Range, rngTarget As Range
  Set aRng = Selection.Range
  If Len(aRng.Text) > 0 Then
    sPath = ActiveDocument.Path & Application.PathSeparator
    Set docSS = GetSS(sPath)
    Set rngTarget = docSS.Range
    rngTarget.Collapse Direction:=wdCollapseEnd
    rngTarget.Text = vbCr & aRng.Text
  End If
End Sub

Function GetSS(sPath As String) As Document
  Dim aDoc As Document
  For Each aDoc In Documents
    If aDoc.FullName = sPath & sSS Then
      Set GetSS = aDoc
      Exit For
    End If
  Next aDoc
  If GetSS Is Nothing Then
    Set GetSS = Documents.Add()
    GetSS.SaveAs FileName:=sPath & sSS
  End If
End Function
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote