The following function properly returns the My Documents path on all my client's systems except one. Its a Win8 system and the IT person changed My Documents to be on a server. I get a error 76, path not found from pappWord.System.PrivateProfileString. If I run as an .accdb on the system it returns the value properly so its something with the .accde.
My references doesn't show any bad references and here's what I've included:
Visual Basic for Applications
Microsoft Access 12.0 Object Library
OLE Automation
Microsoft Office 12.0 Access database engine Object
Microsoft Excel 12.0 Object Library
Microsoft Office 12.0 Object Library
Microsoft Scripting Runtime
Microsoft Scriptlet Library
Microsoft Visual Basic for Application Extensibility 5.3
Microsoft Word 12.0 Object Library
Microsoft XML, v6.0
I've confirmed the user is an administrator. Not sure what else to look at?
Thanks.
My references doesn't show any bad references and here's what I've included:
Visual Basic for Applications
Microsoft Access 12.0 Object Library
OLE Automation
Microsoft Office 12.0 Access database engine Object
Microsoft Excel 12.0 Object Library
Microsoft Office 12.0 Object Library
Microsoft Scripting Runtime
Microsoft Scriptlet Library
Microsoft Visual Basic for Application Extensibility 5.3
Microsoft Word 12.0 Object Library
Microsoft XML, v6.0
I've confirmed the user is an administrator. Not sure what else to look at?
Thanks.
Code:
Public Function MyDocumentsPath() As String
' Comments:
' Params :
' Returns : String
' Modified:
'Written by Helen Feddema 8/14/98
'Last modified 5-May-2006
'This is the Office path
Dim pappWord As Word.Application
Dim strPath As String
On Error GoTo ErrorHandler
Set pappWord = GetObject(Class:="Word.Application")
'The following line should return the Docs path, but it actually returns
'the current path most of the time, so it is not reliable
'DocsPath = pappWord.Options.DefaultFilePath(wdDocumentsPath) & "\"
strPath = pappWord.System.PrivateProfileString("", _
"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", _
"Personal")
' See if the folder exists
If Len(Dir(strPath, vbDirectory)) = 0 Then
' Nope, build it!
MkDir strPath
End If
MyDocumentsPath = strPath
ErrorHandlerExit:
Exit Function
ErrorHandler:
If err = 429 Then
'Word is not running; open Word with CreateObject
Set pappWord = CreateObject(Class:="Word.Application")
Resume Next
Else
MsgBox "Error No: " & err.Number & "; Description: " & VBA.err.Description
Resume ErrorHandlerExit
End If
End Function