msoFileDialogFolderPicker macro operates unexpectedly

astepawayfromx

New Member
Joined
Jul 10, 2013
Messages
8
The Macro below is supposed to copy a a tab, open a dialog box prompting me to select a folder, and to save the new file with read only recommended and marked as final using the filename in cell I4. It mostly works, but when I select a folder, it always saves in that folder's parent folder. So if my directory is Customer>A>Autozone and I select Autozone, it saves in A. I cannot for the life of me figure out why it is doing this and any help you can provide would be hugely appreciated.

Code:
Sub Adjust_and_Save()'
' Adjust_and_Save Macro
'






Dim ThisFile As String
InitialFileName = Range("I4").Value


ActiveSheet.Select
ActiveSheet.Copy




   Dim fldr As FileDialog
    Dim sPath As String
    Set fldr = Application.FileDialog(msoFileDialogFolderPicker)


    With fldr
        .Title = "Select folder"
        .AllowMultiSelect = False
        If .Show = -1 Then
            sPath = .SelectedItems(1)
        End If
    End With






    ActiveWorkbook.SaveAs Filename:=InitialFileName & ".xlsx", Password:="", WriteResPassword:="", ReadOnlyRecommended:=True, CreateBackup:=False
ActiveWorkbook.Final = True
Application.DisplayAlerts = True






ActiveWorkbook.Close






 End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Seems like you are not adding the sPath when you are saving the file. Try changing the SaveAs part of the code to Filename:=sPath & "\" & InitialFileName & ".xlsx". Not sure if you need the slash or not.
 
Upvote 0

Forum statistics

Threads
1,216,119
Messages
6,128,946
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top