Using VBA in MS Project 2003 and working with a Word Document I try to create a new style using Function CreateStyleHeadingTask(NameStyle As String) As Style Set CreateStyleHeadingTask = Nothing If Not wdDoc Is Nothing Then With wdDoc Set CreateStyleHeadingTask = .Styles.Add(Name:=NameStyle, Type:=wdStyleTypeParagraph) '// .Styles.Add Name:=NameStyle, Type:=wdStyleTypeParagraph With .Styles(NameStyle).Font .Size = 14 .Bold = True '// .Color = wdColorBlue .Color = wdColorRed End With Set CreateStyleHeadingTask = .Styles(NameStyle) End With End If End Function
This will crash as soon as I execute the Set CreateStyleHeadingTask statement. If I remove the 'Set CreateStyleheadingTask =' it doesn't crash. What is wrong and how can I correct it?