Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-31-2015, 09:20 AM
Jazz43 Jazz43 is offline Change only last line of Selection Windows 7 64bit Change only last line of Selection Office 2010 64bit
Advanced Beginner
Change only last line of Selection
 
Join Date: Oct 2009
Posts: 51
Jazz43 is on a distinguished road
Default Change only last line of Selection

Hello,

I'm quite new to programming with VBA and im really struggling with finding appropriate commands for it.
So basically what i want to do is to add a border around a selection with VBA. That already works fine (with Selection.Borders) but i also want to have a small space after the border. I tried it with Selection.Paragraph.SpaceAfter, which works fine, but I only want to apply it to the last line, the spaces in the text shouldnt change. Any idea how to do that?



Thanks for any help!
Reply With Quote
  #2  
Old 02-01-2015, 12:20 AM
gmayor's Avatar
gmayor gmayor is offline Change only last line of Selection Windows 7 64bit Change only last line of Selection Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

What is it that is selected? Space after applies to all the paragraphs within the selected range.

If you want something that applies only to the last paragraph in the range then you must tell the macro to limit to that paragraph e.g.

Code:
Selection.Paragraphs.Last.SpaceAfter =
or provide the index number of the paragraph e.g.
Code:
Selection.Paragraphs(3).SpaceAfter =
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 02-03-2015, 07:26 AM
Jazz43 Jazz43 is offline Change only last line of Selection Windows 7 64bit Change only last line of Selection Office 2010 64bit
Advanced Beginner
Change only last line of Selection
 
Join Date: Oct 2009
Posts: 51
Jazz43 is on a distinguished road
Default

There are many paragraphs and i want to change only the last one. My temporary solution was to move the cursor one to the right and one to the left, so the selection is removed but it works fine with .Last, thank you!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Change only last line of Selection Change color according with dropdown selection spk Word VBA 43 07-31-2022 03:51 PM
Change only last line of Selection How to remove a new line from a selection only rajeshkhan808 Word 2 09-13-2014 08:36 PM
Change only last line of Selection Selection of all Text for a specific page in word is spanning selection across pages ramsgarla Word VBA 9 12-05-2012 03:23 AM
Change only last line of Selection Change cell color when selection is made from a drop down list fedcco Excel 12 08-28-2012 10:43 PM
Don't indent the fist line of the first paragraph after a style change Inspirement Word 1 04-08-2012 05:30 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:49 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