Reading Resources and Resource properties in macros 
Author Message
 Reading Resources and Resource properties in macros

Hello

I try to see the project resources with a macro. I tried different examples
I found in the Help files, e.g. this one below:

    Dim R As Long, Names As String

    For R = 1 To ActiveProject.Resources.Count
        Names = ActiveProject.Resources(R).Name & ", " & Names
    Next R

    Names = Left$(Names, Len(Names) - Len(ListSeparator & " "))
    MsgBox Names

At anytime I tried to run it, I've an error message:
"Run-time
error'91'Object variable or With block variable not set"

Is it a library problem ?

Why cant't I use the Resources object to read his properties neither the
Resource object ?

Thank in advance

Jordi



Sat, 21 Jun 2003 23:37:27 GMT  
 Reading Resources and Resource properties in macros
Bruggimann

Surprising. The code is ok and should run without errors. Can you post your
mpp file (ensure that size is below 90k by deleting all the tasks and just 3
resources).

Regards
Venkata Krishna


Quote:
> Hello

> I try to see the project resources with a macro. I tried different
examples
> I found in the Help files, e.g. this one below:

>     Dim R As Long, Names As String

>     For R = 1 To ActiveProject.Resources.Count
>         Names = ActiveProject.Resources(R).Name & ", " & Names
>     Next R

>     Names = Left$(Names, Len(Names) - Len(ListSeparator & " "))
>     MsgBox Names

> At anytime I tried to run it, I've an error message:
> "Run-time
> error'91'Object variable or With block variable not set"

> Is it a library problem ?

> Why cant't I use the Resources object to read his properties neither the
> Resource object ?

> Thank in advance

> Jordi



Sun, 22 Jun 2003 08:42:23 GMT  
 Reading Resources and Resource properties in macros

Jordi

In your project you have blank resource rows i.e. resource id's 1 to 6 are blank. Your valid resources are only of id's 7 to 9. So in the your program loop when R=1, it is trying to access the properties of resource 1 as ActiveProject.Resources(1).Name where as the resource actually does not exist. This will generate an error. So in your loop, you need to see if the resource is nothing and access it's properties only if the resource is not nothing. I have added the required code, which is in bold.

Sub ResourcesTest()
    Dim R As Long, Names As String

    For R = 1 To ActiveProject.Resources.Count
        If Not ActiveProject.Resources(R) Is Nothing Then
            Names = ActiveProject.Resources(R).Name & ", " & Names
        End If
    Next R

    Names = Left$(Names, Len(Names) - Len(ListSeparator & " "))
    MsgBox Names
End Sub

Regards
Venkata Krishna

Quote:

> Thank's Venkata for your quick answer !

> I tried to reduce my mpp file as requested but can't clear it under 200 K;
> why ? is there some masked things within it ?

> Further your answer I tried to run the code in a new project and it worked
> !!! What is the problem with that file ?

> Thank's in advance for your help.

> Jordi



Mon, 23 Jun 2003 01:25:46 GMT  
 Reading Resources and Resource properties in macros
Thank's a lot for your quick and usefull help !

... and a Happy new Year ;-)

Jordi


Jordi

In your project you have blank resource rows i.e. resource id's 1 to 6 are
blank. Your valid resources are only of id's 7 to 9. So in the your program
loop when R=1, it is trying to access the properties of resource 1 as
ActiveProject.Resources(1).Name where as the resource actually does not
exist. This will generate an error. So in your loop, you need to see if the
resource is nothing and access it's properties only if the resource is not
nothing. I have added the required code, which is in bold.

Sub ResourcesTest()
    Dim R As Long, Names As String

    For R = 1 To ActiveProject.Resources.Count
        If Not ActiveProject.Resources(R) Is Nothing Then
            Names = ActiveProject.Resources(R).Name & ", " & Names
        End If
    Next R

    Names = Left$(Names, Len(Names) - Len(ListSeparator & " "))
    MsgBox Names
End Sub

Regards
Venkata Krishna


Quote:
> Thank's Venkata for your quick answer !

> I tried to reduce my mpp file as requested but can't clear it under 200 K;
> why ? is there some masked things within it ?

> Further your answer I tried to run the code in a new project and it worked
> !!! What is the problem with that file ?

> Thank's in advance for your help.

> Jordi



Mon, 23 Jun 2003 01:30:51 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Good resource for getobject properties? read inside please

2. booking a resource then changing the meeting resource

3. Adding resources to Global Resource Pool

4. adding resources to the resource sheet in ms project using vba

5. Getting a drop down resource list when filtering by resource and date range

6. Resources in a resource pool in date range

7. Replace project resources with pool resources

8. Shared Resources/Resource Pool

9. Making a Resource file, or Data resource in a Module

10. Resource files and Custom resource

11. minimize resources with image or pictureBox or resource???

12. Resource Files and Resource Strings

 

 
Powered by phpBB® Forum Software