Save as sub folder limitations

Newguytrying

New Member
Joined
Nov 12, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi All

This is my first post but the this website has helped me tremendously in my learning curve of VBA code. My knowledge on VBA is still basic.

In my workbook I have a button to save a file with a specified filename to a specific location. My problem is no matter what methods I try to save the file I always end up at subfolder 3 (folder test2) and folder 4 is in the name with filename1. Screenshot provided.

I did read something about long path registry but this did not help.

Best way round it so far is to use Application.GetSaveAsFilename and set default file location in excel save settings. This scenario is not ideal long term.

Sub Save_Name1()

Dim filename As String
FileName1 = testname


Dim fPth As Object
Set fPth = Application.FileDialog(msoFileDialogSaveAs)


With Application.FileDialog(msoFileDialogSaveAs)
.InitialFileName = "C:\test\test1\test2\test3" & filename1
.Title = "Save your File"
.FilterIndex = 2
.InitialView = msoFileDialogViewList
.Show
Application.EnableEvents = False
On Error GoTo NoSave
ThisWorkbook.SaveAs filename:=.SelectedItems(1), FileFormat:=52
Exit Sub

NoSave:
Application.EnableEvents = True
'MsgBox "Cannot save as File " & FName & " already open."
On Error GoTo 0


End With
End Sub

1668269678135.png


Any hep is greatly appreciated.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi Newguytrying,

maybe add a backslash like

VBA Code:
  .InitialFileName = "C:\test\test1\test2\test3\" & filename1

Ciao,
Holger
 
Upvote 0
Thanks for your quick reply HaHoBe. That worked, can't believe I did not think of something so obvious. This directory 101.

Thank you again, really appreciate it.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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