![]() |
#6
|
|||
|
|||
![]()
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 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 Last edited by gmaxey; 03-08-2017 at 03:30 PM. |
|
![]() |
||||
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 |
![]() |
Triadragon | Excel | 3 | 05-02-2016 11:48 AM |
![]() |
DanNatCorning | Word VBA | 1 | 04-29-2016 10:47 PM |
![]() |
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 |