Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 11-08-2023, 01:43 AM
RobiNew RobiNew is offline Find and format lines of verse Windows 10 Find and format lines of verse Office 2016
Competent Performer
Find and format lines of verse
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default


Hi, Gmaxey! Thank you for the information on status flag. It looks as if Vivka had never stopped learnig. Some (like myself) are much slower. And thank you for the suggestions and the new code, which works perfectly on its own but misses the penultimate line of verse when inserted (with obvious modifications) in a larger macro. All the best.
Reply With Quote
  #17  
Old 11-08-2023, 05:16 AM
vivka vivka is offline Find and format lines of verse Windows 7 64bit Find and format lines of verse Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

RobiNew, thank you again for good words about my modest help! Greg, thank you for sharing your precious knowledge! Regarding your comments: 1) I thought that 'as Range' was optional when delcaring a range (from now on I will remember that a range MUST be explicitely declared); 2) I fully agree that exiting the sub leaves the final commands unexecuted. Now it's clear why you keep using lbl_exit. Thank you for one more lesson!
Reply With Quote
  #18  
Old 11-08-2023, 06:44 AM
gmaxey gmaxey is online now Find and format lines of verse Windows 10 Find and format lines of verse Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

vivka,


You thought correctly. It is optional. All variables that are implicitly declared are of type Variant. Variables of type Variant require more memory resources than most other variables. While in the case we have at present, it probably doesn't mater but generally your code will be more efficient if you declare variables explicitly and with a specific data type.


Code:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
'Illustrates an implicit variable (not declared using a declaration statement e.g., Dim)
  Set oRng = ActiveDocument.Range
  oRng.Select
lbl_Exit:
  Exit Sub
End Sub
Sub ScratchMacroII()
'A basic Word Macro coded by Gregory K. Maxey
'Illustrates an two explicit variables 1) The compilier resolves as variant 2) Is declared as variant
Dim oRng
Dim oRng2 As Variant
  Set oRng = ActiveDocument.Range
  'Notice after you type oRng. that the properties and methods of the Word range object do not appear.
  oRng.Select
  Set oRng2 = ActiveDocument.Range
  'Notice after you type oRng2. that the properties and methods of the Word range object do not appear.
  oRng2.InsertAfter "more text"
lbl_Exit:
  Exit Sub
End Sub
Sub ScratchMacroIII()
'A basic Word Macro coded by Gregory K. Maxey
'Illustrates an explicit variable set to a specific data type
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  'Notice after you type oRng. that the properties and methods of the Word range object do not appear.
  oRng.Select
  'Note: I typically use the OptionExplicit statement at the top of my code window to force me to
  'explicity declare all variables.  For example, your code would not compile because you have
  'an implicit variable "Para"
lbl_Exit:
  Exit Sub
End Sub
Sub ScratchMacroIV()
'A basic Word Macro coded by Gregory K. Maxey
'Why to I used the lbl_Exit and Exit Sub lines.
  MsgBox "Mainly as a matter of style and practice." & vbCr + vbCr _
      & "I find myself updating a lot of code written by others weeks, years or decaces ago" _
      & " and I use those two lines as my marker that I have finished revising a procedure."
  MsgBox "Secondarily it is my escape clause from a procedure." & vbCr + vbCr _
      & "One of my earlier mentors told me that while it didn't matter anymore (if it ever did) he just never liked to reach" _
      & " the End Sub line in procedure." _
      & " I also use it to escape err handling labels and as a exit point after error handling."
  On Error GoTo Err_Handler
  Err.Raise 6
lbl_Exit:
  Exit Sub
Err_Handler:
  Resume lbl_Exit
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #19  
Old 11-08-2023, 09:04 AM
vivka vivka is offline Find and format lines of verse Windows 7 64bit Find and format lines of verse Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Thumbs up

Thank you, Greg, for your detailed explanation! I will carefully analyze your examples. By the way, your site is one of my bookmarks. A few days ago I recommended it to a visitor of a Ukrainian computer forum.
Reply With Quote
  #20  
Old 11-08-2023, 09:23 AM
gmaxey gmaxey is online now Find and format lines of verse Windows 10 Find and format lines of verse Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Glad to help. Thanks
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Format Word Document - Remove timestamps on individual lines lbeck Word 4 06-21-2023 12:47 PM
How do I format indented bulleted lines??? HELP PLEASE!!! nicholeproffitt Word 1 02-05-2015 05:42 PM
Find and format lines of verse Print table and on verse form vba LaercioNB Excel 1 08-09-2013 06:03 PM
How to remove unwanted lines - I cannot even find how/where they are inserted! nickib Word 7 08-09-2013 06:01 AM
Find and format lines of verse Find and Replace multiple lines/paragraphs jcw Word 1 11-18-2011 11:47 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:49 AM.


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