Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 06-21-2023, 12:47 AM
teachwrite teachwrite is offline Help with debugging a simple macro to cut and paste selected text to end of document Windows 11 Help with debugging a simple macro to cut and paste selected text to end of document Office 2021
Novice
 
Join Date: Jun 2023
Posts: 3
teachwrite is on a distinguished road
Default

I know its been a while since this post, but can someone suggest how to modify this macro so that the selected words are pasted at the bottom of a different document, rather than the same doc? (I want them pasted at the end of a style sheet). Thanks!

Quote:
Originally Posted by BrianHoard View Post
Hi,
I'm very new to VBA, but hopefully this can help.
In my code below, rather than using the clipboard, I'm storing your selection as formatted text. Writing that to the end of the document, then deleting the original selection. After the write to the end of the doc, I add a carriage return, (vbCr).

I also added a message in case nothing was selected.
I tested this with an image in the selection and it also worked fine.


Code:
Sub MoveToOutTakes()
  
  Dim docEnd As Range
  Set docEnd = ActiveDocument.Range
  docEnd.Collapse direction:=collapseEnd
  
  Dim sel As Range
  Set sel = Selection.FormattedText
  
  If (sel.Start = sel.End) Then
    Call MsgBox(Prompt:="Nothing selected.", Buttons:=vbInformation)
  End If
  
  docEnd.FormattedText = sel
  docEnd.InsertAfter (vbCr)
  sel.Delete

End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with debugging a simple macro to cut and paste selected text to end of document Keep text selected after paste dabbler Word 14 01-11-2021 09:54 AM
Help with debugging a simple macro to cut and paste selected text to end of document Copy selected text from one document and paste to new document in same position on the page gasparik Word VBA 1 05-11-2020 05:41 AM
Help with debugging a simple macro to cut and paste selected text to end of document Find and Replace Selected Text or Macro for finding selected text mrplastic Word VBA 4 12-20-2019 01:25 PM
Help with debugging a simple macro to cut and paste selected text to end of document Help debugging a Macro that merges individual word docs into one document vincenzo345 Word VBA 4 12-01-2017 11:25 AM
Help with debugging a simple macro to cut and paste selected text to end of document Macro (debugging) JACKsparrow Word VBA 1 03-09-2016 02:47 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:55 PM.


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