A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Get PST file path string



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 20th 07, 05:08 PM posted to microsoft.public.outlook.program_vba
Diamonds_Mine
external usenet poster
 
Posts: 11
Default Get PST file path string

I found the following Outlook code from an MVP to get the path/names of the
pst files in use and write the results to the immediate window. However, I'd
like to write the results to a text file instead (preferably with the
username as part of the filename); for example: C:\data\jdoe.txt or if not
just C:\data\olPST.txt. Thanks in advance for your assistance.


Sub EnumStorePaths()
'returns results in immediate window

Dim fld As Outlook.MAPIFolder
Dim strPath As String
On Error Resume Next
For Each fld In Application.Session.Folders
strPath = GetStorePath(fld.StoreID)
Debug.Print fld.Name, strPath
Next

End Sub


Function GetStorePath(strStoreID As String)
Dim intStart As Integer
Dim intEnd As Integer
Dim strProvider As String
Dim strPathRaw As String
intStart = InStr(9, strStoreID, "0000") + 4
intEnd = InStr(intStart, strStoreID, "00")
strProvider = _
Mid(strStoreID, intStart, intEnd - intStart)
strProvider = Hex2ToString(strProvider)
Select Case LCase(strProvider)
Case "mspst.dll", "pstprx.dll"
If Right(strStoreID, 6) = "000000" Then
'2003
intStart = InStrRev(strStoreID, "00000000") + 8
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex4ToString(strPathRaw))
Else
'97
intStart = InStrRev(strStoreID, "000000") + 6
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex2ToString(strPathRaw))
End If

Case "msncon.dll"
intStart = InStrRev(strStoreID, _
"00", Len(strStoreID) - 2) + 2
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex2ToString(strPathRaw))
Case "emsmdb.dll"
GetStorePath = "Exchange store"
Case Else
GetStorePath = "Unknown store path"
End Select
End Function

Public Function Hex4ToString(Data As String) As String
Dim strTemp As String
Dim strAll As String
Dim i As Integer
For i = 1 To Len(Data) Step 4
strTemp = Mid(Data, i, 4)
strTemp = "&H" & Right(strTemp, 2) & Left(strTemp, 2)
strAll = strAll & ChrW(CDec(strTemp))
Next
Hex4ToString = strAll
End Function

Public Function Hex2ToString(Data As String) As String
Dim strTemp As String
Dim strAll As String
Dim i As Integer
For i = 1 To Len(Data) Step 2
strTemp = "&H" & Mid(Data, i, 2)
strAll = strAll & ChrW(CDec(strTemp))
Next
Hex2ToString = strAll
End Function
  #2  
Old February 20th 07, 10:32 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default Get PST file path string

You can use the NameSpace.CurrentUser property to get the name of the logged
on user, and the TextStream object from the Microsoft Scripting Runtime
Library to write to a text file.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Diamonds_Mine" wrote:

I found the following Outlook code from an MVP to get the path/names of the
pst files in use and write the results to the immediate window. However, I'd
like to write the results to a text file instead (preferably with the
username as part of the filename); for example: C:\data\jdoe.txt or if not
just C:\data\olPST.txt. Thanks in advance for your assistance.


Sub EnumStorePaths()
'returns results in immediate window

Dim fld As Outlook.MAPIFolder
Dim strPath As String
On Error Resume Next
For Each fld In Application.Session.Folders
strPath = GetStorePath(fld.StoreID)
Debug.Print fld.Name, strPath
Next

End Sub


Function GetStorePath(strStoreID As String)
Dim intStart As Integer
Dim intEnd As Integer
Dim strProvider As String
Dim strPathRaw As String
intStart = InStr(9, strStoreID, "0000") + 4
intEnd = InStr(intStart, strStoreID, "00")
strProvider = _
Mid(strStoreID, intStart, intEnd - intStart)
strProvider = Hex2ToString(strProvider)
Select Case LCase(strProvider)
Case "mspst.dll", "pstprx.dll"
If Right(strStoreID, 6) = "000000" Then
'2003
intStart = InStrRev(strStoreID, "00000000") + 8
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex4ToString(strPathRaw))
Else
'97
intStart = InStrRev(strStoreID, "000000") + 6
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex2ToString(strPathRaw))
End If

Case "msncon.dll"
intStart = InStrRev(strStoreID, _
"00", Len(strStoreID) - 2) + 2
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex2ToString(strPathRaw))
Case "emsmdb.dll"
GetStorePath = "Exchange store"
Case Else
GetStorePath = "Unknown store path"
End Select
End Function

Public Function Hex4ToString(Data As String) As String
Dim strTemp As String
Dim strAll As String
Dim i As Integer
For i = 1 To Len(Data) Step 4
strTemp = Mid(Data, i, 4)
strTemp = "&H" & Right(strTemp, 2) & Left(strTemp, 2)
strAll = strAll & ChrW(CDec(strTemp))
Next
Hex4ToString = strAll
End Function

Public Function Hex2ToString(Data As String) As String
Dim strTemp As String
Dim strAll As String
Dim i As Integer
For i = 1 To Len(Data) Step 2
strTemp = "&H" & Mid(Data, i, 2)
strAll = strAll & ChrW(CDec(strTemp))
Next
Hex2ToString = strAll
End Function

  #3  
Old February 20th 07, 10:48 PM posted to microsoft.public.outlook.program_vba
Diamonds_Mine
external usenet poster
 
Posts: 11
Default Get PST file path string

Thank you Eric; unfortunately I'm new to this and am not sure how to write
it, but will research. One more question -- the code below, can it only be
run from within Outlook or is there a way to run it using a vb script?

"Eric Legault [MVP - Outlook]" wrote:

You can use the NameSpace.CurrentUser property to get the name of the logged
on user, and the TextStream object from the Microsoft Scripting Runtime
Library to write to a text file.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Diamonds_Mine" wrote:

I found the following Outlook code from an MVP to get the path/names of the
pst files in use and write the results to the immediate window. However, I'd
like to write the results to a text file instead (preferably with the
username as part of the filename); for example: C:\data\jdoe.txt or if not
just C:\data\olPST.txt. Thanks in advance for your assistance.


Sub EnumStorePaths()
'returns results in immediate window

Dim fld As Outlook.MAPIFolder
Dim strPath As String
On Error Resume Next
For Each fld In Application.Session.Folders
strPath = GetStorePath(fld.StoreID)
Debug.Print fld.Name, strPath
Next

End Sub


Function GetStorePath(strStoreID As String)
Dim intStart As Integer
Dim intEnd As Integer
Dim strProvider As String
Dim strPathRaw As String
intStart = InStr(9, strStoreID, "0000") + 4
intEnd = InStr(intStart, strStoreID, "00")
strProvider = _
Mid(strStoreID, intStart, intEnd - intStart)
strProvider = Hex2ToString(strProvider)
Select Case LCase(strProvider)
Case "mspst.dll", "pstprx.dll"
If Right(strStoreID, 6) = "000000" Then
'2003
intStart = InStrRev(strStoreID, "00000000") + 8
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex4ToString(strPathRaw))
Else
'97
intStart = InStrRev(strStoreID, "000000") + 6
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex2ToString(strPathRaw))
End If

Case "msncon.dll"
intStart = InStrRev(strStoreID, _
"00", Len(strStoreID) - 2) + 2
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex2ToString(strPathRaw))
Case "emsmdb.dll"
GetStorePath = "Exchange store"
Case Else
GetStorePath = "Unknown store path"
End Select
End Function

Public Function Hex4ToString(Data As String) As String
Dim strTemp As String
Dim strAll As String
Dim i As Integer
For i = 1 To Len(Data) Step 4
strTemp = Mid(Data, i, 4)
strTemp = "&H" & Right(strTemp, 2) & Left(strTemp, 2)
strAll = strAll & ChrW(CDec(strTemp))
Next
Hex4ToString = strAll
End Function

Public Function Hex2ToString(Data As String) As String
Dim strTemp As String
Dim strAll As String
Dim i As Integer
For i = 1 To Len(Data) Step 2
strTemp = "&H" & Mid(Data, i, 2)
strAll = strAll & ChrW(CDec(strTemp))
Next
Hex2ToString = strAll
End Function

  #4  
Old February 20th 07, 11:06 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default Get PST file path string

Yes, you can convert your code to VBScript and have it run out-of-process
from Outlook. However, if you aren't using Outlook 2007 with "code trusting"
enabled, then some object model calls (like CurrentUser) will generate a
security warning dialog.

Here's a reference you can use for writing to a file:

TextStream Object:
http://msdn.microsoft.com/library/en...asp?frame=true

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Diamonds_Mine" wrote:

Thank you Eric; unfortunately I'm new to this and am not sure how to write
it, but will research. One more question -- the code below, can it only be
run from within Outlook or is there a way to run it using a vb script?

"Eric Legault [MVP - Outlook]" wrote:

You can use the NameSpace.CurrentUser property to get the name of the logged
on user, and the TextStream object from the Microsoft Scripting Runtime
Library to write to a text file.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Diamonds_Mine" wrote:

I found the following Outlook code from an MVP to get the path/names of the
pst files in use and write the results to the immediate window. However, I'd
like to write the results to a text file instead (preferably with the
username as part of the filename); for example: C:\data\jdoe.txt or if not
just C:\data\olPST.txt. Thanks in advance for your assistance.


Sub EnumStorePaths()
'returns results in immediate window

Dim fld As Outlook.MAPIFolder
Dim strPath As String
On Error Resume Next
For Each fld In Application.Session.Folders
strPath = GetStorePath(fld.StoreID)
Debug.Print fld.Name, strPath
Next

End Sub


Function GetStorePath(strStoreID As String)
Dim intStart As Integer
Dim intEnd As Integer
Dim strProvider As String
Dim strPathRaw As String
intStart = InStr(9, strStoreID, "0000") + 4
intEnd = InStr(intStart, strStoreID, "00")
strProvider = _
Mid(strStoreID, intStart, intEnd - intStart)
strProvider = Hex2ToString(strProvider)
Select Case LCase(strProvider)
Case "mspst.dll", "pstprx.dll"
If Right(strStoreID, 6) = "000000" Then
'2003
intStart = InStrRev(strStoreID, "00000000") + 8
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex4ToString(strPathRaw))
Else
'97
intStart = InStrRev(strStoreID, "000000") + 6
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex2ToString(strPathRaw))
End If

Case "msncon.dll"
intStart = InStrRev(strStoreID, _
"00", Len(strStoreID) - 2) + 2
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex2ToString(strPathRaw))
Case "emsmdb.dll"
GetStorePath = "Exchange store"
Case Else
GetStorePath = "Unknown store path"
End Select
End Function

Public Function Hex4ToString(Data As String) As String
Dim strTemp As String
Dim strAll As String
Dim i As Integer
For i = 1 To Len(Data) Step 4
strTemp = Mid(Data, i, 4)
strTemp = "&H" & Right(strTemp, 2) & Left(strTemp, 2)
strAll = strAll & ChrW(CDec(strTemp))
Next
Hex4ToString = strAll
End Function

Public Function Hex2ToString(Data As String) As String
Dim strTemp As String
Dim strAll As String
Dim i As Integer
For i = 1 To Len(Data) Step 2
strTemp = "&H" & Mid(Data, i, 2)
strAll = strAll & ChrW(CDec(strTemp))
Next
Hex2ToString = strAll
End Function

  #5  
Old February 20th 07, 11:22 PM posted to microsoft.public.outlook.program_vba
Diamonds_Mine
external usenet poster
 
Posts: 11
Default Get PST file path string

Apologies, but I need some "hand holding" -- what do I use to convert it to
VBScript?

"Eric Legault [MVP - Outlook]" wrote:

Yes, you can convert your code to VBScript and have it run out-of-process
from Outlook. However, if you aren't using Outlook 2007 with "code trusting"
enabled, then some object model calls (like CurrentUser) will generate a
security warning dialog.

Here's a reference you can use for writing to a file:

TextStream Object:
http://msdn.microsoft.com/library/en...asp?frame=true

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Diamonds_Mine" wrote:

Thank you Eric; unfortunately I'm new to this and am not sure how to write
it, but will research. One more question -- the code below, can it only be
run from within Outlook or is there a way to run it using a vb script?

"Eric Legault [MVP - Outlook]" wrote:

You can use the NameSpace.CurrentUser property to get the name of the logged
on user, and the TextStream object from the Microsoft Scripting Runtime
Library to write to a text file.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Diamonds_Mine" wrote:

I found the following Outlook code from an MVP to get the path/names of the
pst files in use and write the results to the immediate window. However, I'd
like to write the results to a text file instead (preferably with the
username as part of the filename); for example: C:\data\jdoe.txt or if not
just C:\data\olPST.txt. Thanks in advance for your assistance.


Sub EnumStorePaths()
'returns results in immediate window

Dim fld As Outlook.MAPIFolder
Dim strPath As String
On Error Resume Next
For Each fld In Application.Session.Folders
strPath = GetStorePath(fld.StoreID)
Debug.Print fld.Name, strPath
Next

End Sub


Function GetStorePath(strStoreID As String)
Dim intStart As Integer
Dim intEnd As Integer
Dim strProvider As String
Dim strPathRaw As String
intStart = InStr(9, strStoreID, "0000") + 4
intEnd = InStr(intStart, strStoreID, "00")
strProvider = _
Mid(strStoreID, intStart, intEnd - intStart)
strProvider = Hex2ToString(strProvider)
Select Case LCase(strProvider)
Case "mspst.dll", "pstprx.dll"
If Right(strStoreID, 6) = "000000" Then
'2003
intStart = InStrRev(strStoreID, "00000000") + 8
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex4ToString(strPathRaw))
Else
'97
intStart = InStrRev(strStoreID, "000000") + 6
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex2ToString(strPathRaw))
End If

Case "msncon.dll"
intStart = InStrRev(strStoreID, _
"00", Len(strStoreID) - 2) + 2
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex2ToString(strPathRaw))
Case "emsmdb.dll"
GetStorePath = "Exchange store"
Case Else
GetStorePath = "Unknown store path"
End Select
End Function

Public Function Hex4ToString(Data As String) As String
Dim strTemp As String
Dim strAll As String
Dim i As Integer
For i = 1 To Len(Data) Step 4
strTemp = Mid(Data, i, 4)
strTemp = "&H" & Right(strTemp, 2) & Left(strTemp, 2)
strAll = strAll & ChrW(CDec(strTemp))
Next
Hex4ToString = strAll
End Function

Public Function Hex2ToString(Data As String) As String
Dim strTemp As String
Dim strAll As String
Dim i As Integer
For i = 1 To Len(Data) Step 2
strTemp = "&H" & Mid(Data, i, 2)
strAll = strAll & ChrW(CDec(strTemp))
Next
Hex2ToString = strAll
End Function

  #6  
Old February 20th 07, 11:54 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default Get PST file path string

It's a manual process. You have to make sure you aren't declaring any data
types with your variables, change typed enumerations to numeric values, etc.

Use this for some guidelines:

Visual Basic for Applications Features Not In vbscript:
http://msdn.microsoft.com/library/en...asp?frame=true

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Diamonds_Mine" wrote:

Apologies, but I need some "hand holding" -- what do I use to convert it to
VBScript?

"Eric Legault [MVP - Outlook]" wrote:

Yes, you can convert your code to VBScript and have it run out-of-process
from Outlook. However, if you aren't using Outlook 2007 with "code trusting"
enabled, then some object model calls (like CurrentUser) will generate a
security warning dialog.

Here's a reference you can use for writing to a file:

TextStream Object:
http://msdn.microsoft.com/library/en...asp?frame=true

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Diamonds_Mine" wrote:

Thank you Eric; unfortunately I'm new to this and am not sure how to write
it, but will research. One more question -- the code below, can it only be
run from within Outlook or is there a way to run it using a vb script?

"Eric Legault [MVP - Outlook]" wrote:

You can use the NameSpace.CurrentUser property to get the name of the logged
on user, and the TextStream object from the Microsoft Scripting Runtime
Library to write to a text file.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Diamonds_Mine" wrote:

I found the following Outlook code from an MVP to get the path/names of the
pst files in use and write the results to the immediate window. However, I'd
like to write the results to a text file instead (preferably with the
username as part of the filename); for example: C:\data\jdoe.txt or if not
just C:\data\olPST.txt. Thanks in advance for your assistance.


Sub EnumStorePaths()
'returns results in immediate window

Dim fld As Outlook.MAPIFolder
Dim strPath As String
On Error Resume Next
For Each fld In Application.Session.Folders
strPath = GetStorePath(fld.StoreID)
Debug.Print fld.Name, strPath
Next

End Sub


Function GetStorePath(strStoreID As String)
Dim intStart As Integer
Dim intEnd As Integer
Dim strProvider As String
Dim strPathRaw As String
intStart = InStr(9, strStoreID, "0000") + 4
intEnd = InStr(intStart, strStoreID, "00")
strProvider = _
Mid(strStoreID, intStart, intEnd - intStart)
strProvider = Hex2ToString(strProvider)
Select Case LCase(strProvider)
Case "mspst.dll", "pstprx.dll"
If Right(strStoreID, 6) = "000000" Then
'2003
intStart = InStrRev(strStoreID, "00000000") + 8
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex4ToString(strPathRaw))
Else
'97
intStart = InStrRev(strStoreID, "000000") + 6
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex2ToString(strPathRaw))
End If

Case "msncon.dll"
intStart = InStrRev(strStoreID, _
"00", Len(strStoreID) - 2) + 2
strPathRaw = Mid(strStoreID, intStart)
GetStorePath = Trim(Hex2ToString(strPathRaw))
Case "emsmdb.dll"
GetStorePath = "Exchange store"
Case Else
GetStorePath = "Unknown store path"
End Select
End Function

Public Function Hex4ToString(Data As String) As String
Dim strTemp As String
Dim strAll As String
Dim i As Integer
For i = 1 To Len(Data) Step 4
strTemp = Mid(Data, i, 4)
strTemp = "&H" & Right(strTemp, 2) & Left(strTemp, 2)
strAll = strAll & ChrW(CDec(strTemp))
Next
Hex4ToString = strAll
End Function

Public Function Hex2ToString(Data As String) As String
Dim strTemp As String
Dim strAll As String
Dim i As Integer
For i = 1 To Len(Data) Step 2
strTemp = "&H" & Mid(Data, i, 2)
strAll = strAll & ChrW(CDec(strTemp))
Next
Hex2ToString = strAll
End Function

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
change the cache mode path (.ost file path) bln-ami Outlook - Installation 0 July 18th 06 09:45 AM
PST path and registry Key Xhork Outlook - Installation 0 June 28th 06 04:58 PM
path of .pst file Jyoti Agarwal Outlook - General Queries 2 April 25th 06 06:39 PM
last string in txt file Leech Outlook and VBA 1 February 10th 06 08:13 AM
Cheng the path of PST file fter installation of Outlook 2003 using MST Lion Outlook - Installation 1 February 2nd 06 12:15 AM


All times are GMT +1. The time now is 12:56 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.