Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 03-08-2017, 05:50 AM
gmaxey gmaxey is offline Word.Range Windows 7 32bit Word.Range Office 2016
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

Serpico,

Each of us has our own style of coding and our own style of posting. Some seem to take pleasure in pointing out the quirks or flaws in others and some don't.

Dim Word.Range as Range and Dim Range contained in the same project executed in Word is the same thing. Sometime I use one, sometimes the other. I guess I'm just not very ordinary.

Paul is very rarely in error. Here again he is true to form, both correct and opinionated. Technically, in the example above, lbl_Exit followed by Exit Sub is certainly unnecessary.

However, opinions aside, those two lines of code are in the autotext I use when starting a scratch procedure.

Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey

lbl_Exit:
Exit Sub
End Sub

... and I "ordinarily" use those two lines of code as a flag to myself that I have finished a review of existing code and as a placeholder for error escaping.

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oDoc As Document
  On Error GoTo Err_Handler
  Set oDoc = Documents(2)
lbl_Exit:
  Exit Sub
Err_Handler:
  Select Case Err.Number
    Case Is = 5941: MsgBox "There is no document 2."
    Case Else
  End Select
  Resume lbl_Exit
End Sub
Here is something for you to ponder:

Code:
Sub A()
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  oRng.Text = "Find me. "
  With oRng.Find
    .Text = "Find me."
    While .Execute
      If .Found Then
        MsgBox "Some choose to use use .Found. Is it neccesary or just a quirk?  You decide."
        oRng.Text = "Found"
      End If
    Wend
  End With
End Sub
Sub B()
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  oRng.Text = "Find me. "
  With oRng.Find
    .Text = "Find me."
    While .Execute
     oRng.Text = "Found"
    Wend
  End With
lblExit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/

Last edited by gmaxey; 03-08-2017 at 03:30 PM.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Distribute text in one cell across a range of cells (overcoming selection.range.cells.count bug) slaycock Word VBA 0 02-18-2017 07:00 AM
Word.Range Find if Date range falls within another range Triadragon Excel 3 05-02-2016 11:48 AM
Word.Range Name a Range in a Word Document and then copy that range to the end of the doc w button click DanNatCorning Word VBA 1 04-29-2016 10:47 PM
Word.Range Set Excel Range using Word gbrew584 Word VBA 3 12-07-2015 01:51 PM
Through VBA, export range from Excel to Word duugg Word VBA 0 08-24-2009 07:50 PM

Other Forums: Access Forums

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