Hi guys, thanks for taking the time to look at this problem. I am writing a word macro and am finding it difficult to return a Range object from a function. Here is the code (i have commented out the unneccessary code):
VB Code:
Sub start() Dim aRange As Range aRange = getTestNameAndNumber(ActiveDocument) 'MsgBox testNumber ' MsgBox testName End Sub Public Function getTestNameAndNumber(ByRef aDocument As Document) As Range Dim aRange As Word.Range Set aRange = aDocument.TablesOfContents(1).Range ' Dim i As Integer ' i = 1 ' Do 'If (CInt(Mid(aRange.Sentences.Item(i), 1, 1) = 3)) Then 'Finds the first 3 in contents ' Exit Do ' End If ' i = i + 1 ' Loop While i < aRange.Sentences.Count getTestNameAndNumber = aRange 'aRange.Sentences.Item(i) End Function
It gives the following error "Object variable or With block variable not set (Error 91)"
Thanks for your time
<>GT<>





Reply With Quote