troubleshooting Question

Word macro opening another Word document refuses to work - Run-time error 4172 - path not found but file is there.

Avatar of stephenlecomptejr
stephenlecomptejrFlag for United States of America asked on
Microsoft Word
1 Comment1 Solution3534 ViewsLast Modified:
I keep getting a 4172 run-time error, path not found on line item:  ChangeFileOpenDirectory sPath
When I do a Print sPath in the Immediate window, I get:  Print sPath
C:\Documents and Settings\SLecompt\Application Data\Microsoft\Templates\

And then I physically go in there with Windows Explorer and see that does indeed exist in that path?
Not sure why the error when it does exist?

Here's the full scope of the code which grabs user login - to get the correct My Documents' path.

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

' for the API of the user id's login

Sub Open_ECFax()
' Macro recorded 2/20/2006 by Stephen LeCompte
  Dim sPath As String
  sPath = "C:\Documents and Settings\" & fOSUserName & "\Application Data\Microsoft\Templates\"
  ChangeFileOpenDirectory sPath
  Documents.Open FileName:="Fax.doc", ConfirmConversions:=False, ReadOnly:= _
    False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
    "", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
    Format:=wdOpenFormatAuto, XMLTransform:=""
End Sub

Public Function fOSUserName() As String
On Error GoTo Err_fOSUserName

' Returns the network login name
    Dim lngLen As Long, lngX As Long
    Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If (lngX > 0) Then
        fOSUserName = Left$(strUserName, lngLen - 1)
        fOSUserName = vbNullString
    End If
    Exit Function
    'Call Error_Action(Err, Err.Description, "modCPUName @ fOSUserName", Erl())
    Resume Exit_fOSUserName
End Function
'******************** Code End **************************
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros