Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-28-2024, 08:50 AM
RobiNew RobiNew is offline VBA Word simple macro to select the current paragraph Windows 10 VBA Word simple macro to select the current paragraph Office 2016
Competent Performer
VBA Word simple macro to select the current paragraph
 
Join Date: Sep 2023
Posts: 208
RobiNew is on a distinguished road
Default VBA Word simple macro to select the current paragraph


High! I'm trying to write a simple macro to just select the current paragraph, but with no success. Can anyone help? Thanks!
Reply With Quote
  #2  
Old 09-28-2024, 10:59 AM
gmaxey gmaxey is offline VBA Word simple macro to select the current paragraph Windows 10 VBA Word simple macro to select the current paragraph Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Selection.Paragraphs(1).Range.Select
lbl_Exit:
Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 09-28-2024, 02:17 PM
macropod's Avatar
macropod macropod is offline VBA Word simple macro to select the current paragraph Windows 10 VBA Word simple macro to select the current paragraph Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

Why would you want a macro for that? Simply triple-clicking on a paragraph will select it.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 09-29-2024, 12:08 AM
RobiNew RobiNew is offline VBA Word simple macro to select the current paragraph Windows 10 VBA Word simple macro to select the current paragraph Office 2016
Competent Performer
VBA Word simple macro to select the current paragraph
 
Join Date: Sep 2023
Posts: 208
RobiNew is on a distinguished road
Default

Many thanks, gmaxey and thank you macropod for replying!
The line:
Selection.Paragraphs(1).Range.Select
is just what I needed. I will insert it into a large macro.
Reply With Quote
  #5  
Old 09-29-2024, 02:28 AM
macropod's Avatar
macropod macropod is offline VBA Word simple macro to select the current paragraph Windows 10 VBA Word simple macro to select the current paragraph Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

With VBA, it is rare that anything needs to be selected. Using selections is inefficient, prone to producing screen flicker, and typically leads to the insertion point ending up somewhere completely different from where you started out.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 09-29-2024, 07:01 AM
RobiNew RobiNew is offline VBA Word simple macro to select the current paragraph Windows 10 VBA Word simple macro to select the current paragraph Office 2016
Competent Performer
VBA Word simple macro to select the current paragraph
 
Join Date: Sep 2023
Posts: 208
RobiNew is on a distinguished road
Default

Thanks again, macropod! I need to select a paragraph in oder to format it with a specific language. Is there a way to do it without selecting the paragraph? Cheers!
Reply With Quote
  #7  
Old 09-29-2024, 01:46 PM
macropod's Avatar
macropod macropod is offline VBA Word simple macro to select the current paragraph Windows 10 VBA Word simple macro to select the current paragraph Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

Since you haven't posted the code of which this is part, all I can work with is the initial Selection, for which you could use something like:
Selection.Paragraphs(1).Range.LanguageID = wdBelgianFrench
But even that initial Selection is most likely unnecessary.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 09-29-2024, 11:49 PM
RobiNew RobiNew is offline VBA Word simple macro to select the current paragraph Windows 10 VBA Word simple macro to select the current paragraph Office 2016
Competent Performer
VBA Word simple macro to select the current paragraph
 
Join Date: Sep 2023
Posts: 208
RobiNew is on a distinguished road
Default

Thanks, macropod! Your code line doesn't work. How would you do the trick with Range? All the best!
Reply With Quote
  #9  
Old 09-29-2024, 11:58 PM
macropod's Avatar
macropod macropod is offline VBA Word simple macro to select the current paragraph Windows 10 VBA Word simple macro to select the current paragraph Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

Quote:
Originally Posted by RobiNew View Post
Your code line doesn't work.
It works for me. You can demonstrate it with something as simple as:
Code:
Sub Test()
MsgBox Selection.Paragraphs(1).Range.LanguageID
Selection.Paragraphs(1).Range.LanguageID = wdBelgianFrench
MsgBox Selection.Paragraphs(1).Range.LanguageID
End Sub
where your initial language is something other than Belgian French.
Quote:
Originally Posted by RobiNew View Post
How would you do the trick with Range?
Without seeing your code, it's impossible to say how it should be revised.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 09-30-2024, 12:36 AM
RobiNew RobiNew is offline VBA Word simple macro to select the current paragraph Windows 10 VBA Word simple macro to select the current paragraph Office 2016
Competent Performer
VBA Word simple macro to select the current paragraph
 
Join Date: Sep 2023
Posts: 208
RobiNew is on a distinguished road
Default

High, macropod! I do apologize: your code really works. I can't understand why it didn't the first time I tried it. Many thanks and all the best!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting a tab char at the end of current paragraph RRB Word VBA 5 03-14-2024 01:49 PM
VBA Word simple macro to select the current paragraph 1. Apply to current row. 2. De-select row afterwards. Aengus345 Word VBA 3 02-12-2024 06:28 AM
A macro that moves the current paragraph up or down? New Daddy Word VBA 2 04-13-2014 02:25 PM
VBA Word simple macro to select the current paragraph A simple select for a given math formula Jo-NathanBSChE Excel 1 04-16-2013 03:10 AM
VBA Word simple macro to select the current paragraph How to select the first row of the current table Jennifer Murphy Word VBA 9 01-29-2012 06:50 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:00 AM.


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