DigitBoy
asked on
get outlook folder IDs
Dear all,
is it possible to select a folder in outlook and to export with all subfolders their IDs to a txt file using VB script?
Also from Public folders in outlook.
K rgs
is it possible to select a folder in outlook and to export with all subfolders their IDs to a txt file using VB script?
Also from Public folders in outlook.
K rgs
ASKER
Hi Chris,
the code doesn't work.
No error message.
K rgs
the code doesn't work.
No error message.
K rgs
ASKER
I want to select a folder and export the entryID's.
Did you set the DOS folder path to a valid folder?
ASKER
yes I did
Thecode was tested . Can you step through and see what happens?
ASKER
I've seleced a outlook folder and ran your script. The output folder is also fine.
ASKER
Sorry My mistake. this is a vba code.
ASKER
Is there a way in vbs please? Because this was our orginal question.
Bother!
I knew that and though I tested in Outlook I tried to make it VBS but missed a critical bit!
Chris
I knew that and though I tested in Outlook I tried to make it VBS but missed a critical bit!
Dim fso
Dim txtFile
Set fso = CreateObject("scripting.filesystemobject")
Set txtFile = fso.CreateTextFile(("C:\deleteme\folderIDs.txt"), True)
writeids txtFile, createobject("outlook.Application").ActiveExplorer.CurrentFolder
txtFile.Close
Sub writeids(txtFile, fldr)
Dim subfolder
txtFile.Write fldr.FolderPath & " <<< " & fldr.EntryID & " >>>" & vbCrLf
For Each subfolder In fldr.Folders
writeids txtFile, subfolder
Next
End Sub
Chris
Tested as a VBS this time rather than tried to be clever ;o)
Chris
Chris
ASKER
Hi Chris,
It works :D. Really great.
I have just a small question, is there a possibility to use inputbox "Set txtFile = fso.CreateTextFile(("C:\deleteme\folderIDs.txt"), True)" instead of hardcoded please?
K rgs
It works :D. Really great.
I have just a small question, is there a possibility to use inputbox "Set txtFile = fso.CreateTextFile(("C:\deleteme\folderIDs.txt"), True)" instead of hardcoded please?
K rgs
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hmmm
That took a bit of finding, (fell on a function from Rob van der Woude that seems to do the job). This is based on the pickfolder change I posted last:
Chris
That took a bit of finding, (fell on a function from Rob van der Woude that seems to do the job). This is based on the pickfolder change I posted last:
Dim fso
Dim txtFile
Dim strFile
Set fso = CreateObject("scripting.filesystemobject")
' Set txtFile = fso.CreateTextFile(("C:\deleteme\folderIDs.txt"), True)
strFile = GetFileName( "", "Text files|*.txt" )
' If not fso.FileExists(strFile) Then
' MsgBox "OOPS File NOT found"
' WScript.quit
' End If
Set txtFile = fso.OpenTextFile(strFile, 2, true)
With createobject("outlook.Application")
writeids txtFile, .session.pickfolder
End With
txtFile.Close
Sub writeids(txtFile, fldr)
Dim subfolder
txtFile.Write fldr.FolderPath & " <<< " & fldr.EntryID & " >>>" & vbCrLf
For Each subfolder In fldr.Folders
writeids txtFile, subfolder
Next
End Sub
Function GetFileName( myDir, myFilter )
' http://www.robvanderwoude.com/vbstech_ui_fileopen.php
' This function opens a File Open Dialog and returns the
' fully qualified path of the selected file as a string.
'
' Arguments:
' myDir is the initial directory; if no directory is
' specified "My Documents" is used;
' NOTE: this default requires the WScript.Shell
' object, and works only in WSH, not in HTAs!
' myFilter is the file type filter; format "File type description|*.ext"
' ALL arguments MUST get A value (use "" for defaults), OR otherwise you must
' use "On Error Resume Next" to prevent error messages.
'
' Dependencies:
' Requires NUSRMGRLib (nusrmgr.cpl), available in Windows XP and later.
' To use the default "My Documents" WScript.Shell is used, which isn't
' available in HTAs.
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com
' Standard housekeeping
Dim objDialog
' Create a dialog object
Set objDialog = CreateObject( "UserAccounts.CommonDialog" )
' Check arguments and use defaults when necessary
If myDir = "" Then
' Default initial folder is "My Documents"
objDialog.InitialDir = CreateObject( "WScript.Shell" ).SpecialFolders( "MyDocuments" )
Else
' Use the specified initial folder
objDialog.InitialDir = myDir
End If
If myFilter = "" Then
' Default file filter is "All files"
objDialog.Filter = "All files|*.*"
Else
' Use the specified file filter
objDialog.Filter = myFilter
End If
' Open the dialog and return the selected file name
If objDialog.ShowOpen Then
GetFileName = objDialog.FileName
Else
GetFileName = ""
End If
End Function
Chris
ASKER
Hi Chris,
I have just one small issue and that is I have to rename each time the exported txt file. Is there way to create each time a new txt file please?
K rgs
I have just one small issue and that is I have to rename each time the exported txt file. Is there way to create each time a new txt file please?
K rgs
You rename the file in the dialog as required.
Chris
Chris
ASKER
Hi Chris,
thanks for you quick response.
I have an error "Set objDialog = CreateObject( "UserAccounts.CommonDialog " )" cannot create object.
K rgs
thanks for you quick response.
I have an error "Set objDialog = CreateObject( "UserAccounts.CommonDialog
K rgs
it's xp and works there ... which os do you have?
ASKER
I have win7
ASKER
very nice coding skills.
Set txtFile = fso.CreateTextFile(("C:\de
to point to the file you want to contain the output ... I have added the folder path and some additional characters but if you do want just the ids then delete the surplus.
Open in new window
Chris