Converting VBA in VBS

Hi,

i need to convert the following VBA code into VBS to run it at another PC with CMD.

######Code Starts here######
Sub AddToFavorites()

 'Adds a Public Folder to the list of favorites

 Dim objFolder As Outlook.Folder

 Set objFolder = Application.Session.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders.Item("GR")

 objFolder.AddToPFFavorites

End Sub
#####Code ends here#####

Can someone help me ?
I just found this today and i need it to automatically add some publicfolders to Outlook at some clients.

Many thanks for your suggestions!
Jonas HuberAsked:
Who is Participating?
 
Rgonzo1971Commented:
Hi,

pls try
 'Adds a Public Folder to the list of favorites
 const olPublicFoldersAllPublicFolders=18
 Dim objOutlook As Object
 Dim objFolder As Object

 Set objOutlook = CreateObject("Outlook.Application")

 Set objFolder = objOutlook.Session.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders.Item("GR") 

 objFolder.AddToPFFavorites

Open in new window

Regards
2
 
Jonas HuberAuthor Commented:
Hi,

thank you Rgonzo
that worked after i removed the "as Object" at both of the definitions,
because it led to an script error.
But i thought if i don't define the typ of the variable it would take Variant automatically and it worked.

Regards
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.