Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PickFolder vs Hardcode ...

Status
Not open for further replies.

gwoman

Programmer
Nov 16, 2004
199
US
I have a script that extracts outlook calendar data and puts it into an Excel Spreadsheet. When I give the user the option to pick what calendar folder they want to use the code works perfect ... however I am making this a scheduled task that runs weekly and so I am trying to hardcode the calendar folder and I get an error ...

Here is the code using PickFolder...
SelectCalendarFolder:
'Allow user to select Calendar folder
Set nms = Application.GetNamespace("MAPI")
Set fld = nms.PickFolder
MsgBox nms
MsgBox fld
If fld Is Nothing Then
MsgBox "Please select a Calendar folder"
GoTo SelectCalendarFolder
End If
'Debug.Print "Default item type: " & fld.DefaultItemType
If fld.DefaultItemType <> olAppointmentItem Then
MsgBox "Please select a Calendar folder"
GoTo SelectCalendarFolder
End If

Here is the code where I have hardcoded it ...
SelectCalendarFolder:
'Allow user to select Calendar folder
Set nms = Application.GetNamespace("MAPI")
Set fld = nms.Folders("Aera wide Kaizens Test").Folders

If fld Is Nothing Then
MsgBox "Please select a Calendar folder"
GoTo SelectCalendarFolder
End If
'Debug.Print "Default item type: " & fld.DefaultItemType
If fld.DefaultItemType <> olAppointmentItem Then
MsgBox "Please select a Calendar folder"
GoTo SelectCalendarFolder
End If

Can anyone see what I am doing wrong ... thanks!!!
gwoman
 
[0] You are asking in vbscript forum, so I think you're going to adapt [0.1] the goto statement with am appropriate construction, and [0.2] the "Application" object by creating it, and [0.3] named constant olAppointItem defined explicitly. Otherwise, if you want to get some info on how to do in vba, the following may give you some clue and you've to adapt accordingly to vba construction.

[1]
[tt]'Application be established by createobject()
Set nms = Application.GetNamespace("MAPI")
set ofolder=nms.folders(("Aera wide Kaizens Test")
if not ofolder is nothing then
set fld=ofolder.folders
for each ofld in fld
if ofld.DefaultItemType=1 then 'olAppointmentItem=1
'do thing here on calendar
end if
next
end if
'etc etc [/tt]
 
There is a typo on this line and it should be read like this.
[tt]set ofolder=nms.folders[highlight]([/highlight]"Aera wide Kaizens Test")[/tt]
 
scheduled task? running under what user account? does the system account have access to these folders?

what is your error?

you are using Set fld = nms.Folders("Aera wide Kaizens Test").Folders, so the string defining which folder to pick is "Aera wide Kaizens Test", how does this differ from the string you get back when you ask the user to select it themselves? if the string is no different then see my first question
 
It can run under any user account and yes the folder is a public folder so it does have access to it.
When I show the following variables whe using PickFolder this is what I get ...
nms = MAPI
fld = Aera wide Kaizens Test
So I changed my fld variable as follows:
fld = nms.Folder("Aera wide Kaizens Test")

But I still get the error ... it's either error no. 91 or error no. 438

Thanks
gwoman
 
I don't think you read very carefully what is posted by others and/or what you post in the last message.
 
=)
Actually that is the name of the company I work for ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top