VBA Macro Case Change

H

Hans Flippo

I found this macro on http://www.mvps.org/project/CaseChange.txt. It does
not run in Project 2000 / Visual Basic 6.3, it stops with Runtime error 91
Object variable or With block variable not set.
I have entered values for the text1 column for each task in the project.

What is the problem with this code?

Thanks for your help, Hans Flippo

Sub ChangeCase()
Dim tskTask As Task
Dim UpperOrLower As String

Start:
UpperOrLower = InputBox(Prompt:="Enter 'Upper' or 'Lower'", _
Title:="Conver to Upper or Lower Case?")
If UpperOrLower <> "Upper" And UpperOrLower <> "Lower" Then
MsgBox Prompt:="You did not enter Upper or Lower. Check your spelling",
_
Title:="Error"
GoTo Start
End If

Select Case UpperOrLower
Case "Lower"
For Each tskTask In ActiveProject.Tasks
tskTask.Text1 = LCase(tskTask.Text1)<error 91 here>
Next tskTask

Case "Upper"
For Each tskTask In ActiveProject.Tasks
tskTask.Text1 = UCase(tskTask.Text1)<error 91 here>
Next tskTask
End Select

End Sub
 
J

Jan De Messemaeker

Hi,

You have (a) blank line(s) in your task list; they are interpreted as
Nothing objects in the for each task loop and cannot be handled

You must ALWAYS program these for/next loops ad follows:

for each tsktask in activeproject.tasks
if not tsktask is nothing then
.................
end if
next tsktask

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top