Newguytrying
New Member
- Joined
- Nov 12, 2022
- Messages
- 2
- Office Version
- 365
- Platform
- 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
Any hep is greatly appreciated.
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
Any hep is greatly appreciated.