Link to home
Start Free TrialLog in
Avatar of apollosmintheus
apollosmintheus

asked on

Runtime error 4172 on Save As...

Hi, I installed a macro that allows Word 2007 to remember the last file location opened. The link to the macro was found by one of you wonderful experts here at Experts Exchange: http://forums.mydigitallife.info/threads/21597-Make-Word-2100-remember-the-last-location-it-saved-or-opened-a-document

The macro was written for 2010 and had not yet been tested for 2007.  It does what I wanted it to do, but I've realized now that something in it must be wrong, because the Save As function no longer works, whether I use the keyboard command (F12) or the menu alternative.  It triggers a runtime error 4172.

When I click on Debug, Visual Basic highlights the line: "ChangeFileOpenDirectory MyString" in the next to the last sub:

Function FilePath(iDialog)
    Dim MyString As String
    uProfile = Environ("USERPROFILE")
   
    If FileOrDirExists(uProfile & "\FilePath.txt") Then
        Else: GoTo SkipInput
    End If
   
    Open uProfile & "\FilePath.txt" For Input As #1
    Do While Not EOF(1)
        Line Input #1, MyString
    Loop
    Close #1
   
    ChangeFileOpenDirectory MyString
   
SkipInput:
    If iDialog = "Save" Then
        ActiveDocument.Save
    Else
        Set nDialog = Dialogs(iDialog)
        On Error Resume Next
            With nDialog
                .Show
            End With
        On Error GoTo 0
    End If
           
    Open uProfile & "\FilePath.txt" For Output As #2
        Write #2, CurDir()
    Close #2
   
End Function

I'm afraid VB is greek to me.  Is it obvious to anyone here what's incorrect in the passage?

Many thanks in advance!
Avatar of apollosmintheus
apollosmintheus

ASKER

Oh! Now I see that I get the same error with the regular save command as well (both Ctrl+S and save in the menu).  What does work is if I go into the menu and don't click on save as, but hold the cursor over it and then choose either Word Document or Word 97-2003 Document. Kind of complicated for something I normally do every five minutes.

Avatar of Norie
This problem has something to do with the folder not being found.

What's the value in MyString when you get the error?

Also, what's the Default file location in Options?

If that's not a valid path then change it to one and that should stop the error on SaveAs.

I'm not sure how to fix the function that 'remembers' the last folder but I'm pretty sure that's where the problem is.
What is MyString? Where do I find what the value in it is?

I double-checked the default file location.  Even changed it to make sure it wasn't a folder that had been deleted. I did change some folder names the other day.  But the problem remains.
SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK, thanks.  The message box that pops up says:

Compile error:
Ambiguous name detected: FilePath

Does that mean anything to you?  I'm sorry I'm such a dunce.

I believe that means you've got more than 1 variable with same name

check you might have declared filepath variable twise
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do any of the folders the files are from have spaces?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hmmm.... these three lines seem to have worked.  Let me try this for a while and see. Thanks!