Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-29-2020, 07:10 AM
alex100 alex100 is offline Multiple conditional operators with Find/Execute & move cursor at the end of a range Windows 7 64bit Multiple conditional operators with Find/Execute & move cursor at the end of a range Office 2016
Advanced Beginner
Multiple conditional operators with Find/Execute & move cursor at the end of a range
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default Multiple conditional operators with Find/Execute & move cursor at the end of a range


I have two questions, please...

1) I'm using the code below to change all fonts that have a size of 10. How can I adapt it so that it can also include font sizes smaller than 10? I tried setting the size condition to '.Font.Size <= 10' but all I received was an error.

Code:
Dim MyRange As range
Set MyRange = Selection.range
With MyRange.Find
    .Font.Size = 10
    .Forward = False
    .Replacement.Font.Size = 12
    .Replacement.Font.Name = "Arial"
    .Execute Replace:=wdReplaceAll
   End With
2) Using the following code for pasting, how can I move the cursor at the end of the range? As it is now, it only moves it at the end of the first paragraph.

Code:
Dim pasted_content As range
Set pasted_content = Selection.range
pasted_content.Paste
With pasted_content
    Selection.MoveEnd Unit:=wdParagraph, Count:=1
End With
Thank you!

Alex

Last edited by alex100; 05-29-2020 at 12:44 PM.
Reply With Quote
  #2  
Old 05-29-2020, 02:57 PM
macropod's Avatar
macropod macropod is offline Multiple conditional operators with Find/Execute &amp; move cursor at the end of a range Windows 7 64bit Multiple conditional operators with Find/Execute &amp; move cursor at the end of a range Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You would need to implement a loop, to process point sizes starting at 1 and ending at 10, in 0.5pt increments. For example:
Code:
Dim i as long
With Selection.Range.Find
  .Forward = True
  .Replacement.Font.Size = 12
  .Replacement.Font.Name = "Arial
  .Wrap = wdFindStop
  For i = 2 to 20
    .Font.Size = i / 2
    .Execute Replace:=wdReplaceAll
  Next
 End With
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-30-2020, 02:43 AM
alex100 alex100 is offline Multiple conditional operators with Find/Execute &amp; move cursor at the end of a range Windows 7 64bit Multiple conditional operators with Find/Execute &amp; move cursor at the end of a range Office 2016
Advanced Beginner
Multiple conditional operators with Find/Execute &amp; move cursor at the end of a range
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default

Wonderful, thanks Paul!

As for moving the cursor at the end of a range, I found a solution, although I believe there must be a simpler way to achieve this (like a single instruction). If so, I would love to find out about it! Until then, this is what I'll be using...

Code:
Dim pasted_content As range
Set pasted_content = Selection.range
pasted_content.Paste
With pasted_content
    .Select
    Selection.MoveRight Unit:=wdCharacter, Count:=1
End With
Alex
Reply With Quote
  #4  
Old 05-30-2020, 02:46 AM
macropod's Avatar
macropod macropod is offline Multiple conditional operators with Find/Execute &amp; move cursor at the end of a range Windows 7 64bit Multiple conditional operators with Find/Execute &amp; move cursor at the end of a range Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Is this related to the discussion in: https://www.msofficeforums.com/word-...sted-text.html ?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 05-30-2020, 07:09 AM
alex100 alex100 is offline Multiple conditional operators with Find/Execute &amp; move cursor at the end of a range Windows 7 64bit Multiple conditional operators with Find/Execute &amp; move cursor at the end of a range Office 2016
Advanced Beginner
Multiple conditional operators with Find/Execute &amp; move cursor at the end of a range
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Is this related to the discussion in: https://www.msofficeforums.com/word-...sted-text.html ?
No, not at all. The highlighting subroutine works flawless, and I'm well passed that stage.

Right now I'm just finishing a macro script that involves multiple subroutines (including the highlighting sub) that basically reformats web articles in a standard, easy to read way (nothing fancy, just personal preferences). Apart from that, I also implemented two subroutines that quickly copy/update these docs onto my eBook reader, or print them in Duplex/Booklet format.

By the way, I'd like to thank everyone who answered my questions, including you, Paul. I have no experience in VBA, but the fact that I know some Perl programming, that helped me a lot. To most of my questions I managed to quickly find answers searching Google, but there were times when I could not find the information I needed. That was the time when I posted the questions here. I have no doubt that without your help, I would have stuck, probably giving up at some point.

The 'cursor at the end of a rage' question is for a bug I just discovered, which was due to the fact that after paste, the cursor would not be repositioned at the end of text (as it happens when you use 'Selection.Paste', for example).

Alex
Reply With Quote
  #6  
Old 05-30-2020, 04:12 PM
macropod's Avatar
macropod macropod is offline Multiple conditional operators with Find/Execute &amp; move cursor at the end of a range Windows 7 64bit Multiple conditional operators with Find/Execute &amp; move cursor at the end of a range Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Dim Rng As Range
Set Rng = Selection.Range
Rng.Paste
Rng.Collapse wdCollapseEnd
Rng.Select
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 05-31-2020, 04:57 AM
alex100 alex100 is offline Multiple conditional operators with Find/Execute &amp; move cursor at the end of a range Windows 7 64bit Multiple conditional operators with Find/Execute &amp; move cursor at the end of a range Office 2016
Advanced Beginner
Multiple conditional operators with Find/Execute &amp; move cursor at the end of a range
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default

Thank you!

Alex
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple conditional operators with Find/Execute &amp; move cursor at the end of a range One line find execute in this case is possible? eduzs Word VBA 1 05-18-2020 10:52 AM
Execute a Sub OR routine or macro based on multiple user choices from a dropbox VitorH Word VBA 1 03-29-2019 02:48 AM
Multiple conditional operators with Find/Execute &amp; move cursor at the end of a range How to avoid find.execute moving focus and restore exact view after search diracsbracket Word VBA 3 10-30-2016 03:17 AM
Find Bookmark, move to bookmark, execute code, repeat raymm3852 Word VBA 10 04-15-2016 06:21 PM
Multiple conditional operators with Find/Execute &amp; move cursor at the end of a range Find and Execute cksm4 Word VBA 1 10-22-2011 11:36 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:27 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft