![]() |
|
![]() |
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
![]()
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 |
#2
|
|||
|
|||
![]()
Many Thanks, Brian!
Wow! This macro not only works, I can't see it working—bouncing to the end of the document and back again like the one I recorded does. I wonder if I could beg your help fixing the cousin of the macro you rewrote for me? It, too, works in some documents, but not others. I wrote it to help reorder a sentence—moving a block from the middle to the beginning of the sentence and correcting the capitilazation. Like its cousin, I sometimes get an error message, caused because the macro chokes when asked to paste the text it cut. Here's my code: Sub MoveBlockToBeginningOfSentence() ' ' MoveBlockToBeginningOfSentence Macro ' ' Selection.Cut Application.Run MacroName:="Normal.NewMacros.SentenceLeft" Application.Run MacroName:="Normal.NewMacros.CapitalizeNextLetter" Selection.Paste Application.Run MacroName:="Normal.NewMacros.SentenceLeft" Application.Run MacroName:="Normal.NewMacros.CapitalizeNextLetter" End Sub |
#3
|
|||
|
|||
![]()
Cool, glad the first one helped. For this one, you're calling the following macros: Normal.NewMacros.SentenceLeft and Normal.NewMacros.CapitalizeNextLetter
If you post the contents of those, I could take a look. And/Or, if you post an example document with a before/after of your starting point and what your goal is, that's also very helpful. |
#4
|
|||
|
|||
![]()
Hello Brian,
Here are the two macros called into play by the one that I posted last week. It’s worked for me for about 20 years now, but suddenly quit. Thanks in advance for your help! Sub SentenceLeft() ' ' SentenceLeft Macro ' ' Selection.MoveLeft Unit:=wdSentence, Count:=1 End Sub Sub CapitalizeNextLetter() ' ' CapitalizeNextLetter Macro ' ' Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend Selection.Range.Case = wdToggleCase Selection.MoveLeft Unit:=wdCharacter, Count:=1 End Sub I’ve attached an illustration of the desired effect. By the way, I tried to find a way to get the following joke to work for this illustration, but was unsuccessful: My wife: You need to do more chores around the house. Me: Can we change the subject? My wife: Ok. More chores around the house need to be done by you. |
#5
|
|||
|
|||
![]()
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:
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
dabbler | Word | 14 | 01-11-2021 09:54 AM |
![]() |
gasparik | Word VBA | 1 | 05-11-2020 05:41 AM |
![]() |
mrplastic | Word VBA | 4 | 12-20-2019 01:25 PM |
![]() |
vincenzo345 | Word VBA | 4 | 12-01-2017 11:25 AM |
![]() |
JACKsparrow | Word VBA | 1 | 03-09-2016 02:47 PM |