VBA save workbook excel

miew

New Member
Joined
Jan 15, 2023
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
I trying to save file in a specific folder using VBA but it is only working until folder STUDENT NAME LIST but it supposedly save in folder year 2022. Any suggestions?

```vba
Sub SaveResult()
Dim MyFile As String
MyFile = "\\uni\admin\Course Code\Lecturer Name\Semester\Class\STUDENT NAME LIST \2022" & Sheets("RESULT").Range("A5") & "_" & Sheets("RESULT").Range("E11") & "_" & Sheets("RESULT").Range("E13") & ".xls"

'create result in XLSX format
ActiveWorkbook.SaveAs "\\uni\admin\Course Code\Lecturer Name\Semester\Class\STUDENT NAME LIST \2022" & Sheets("RESULT").Range("A5") & "_" & Sheets("RESULT").Range("E11") & "_" & Sheets("RESULT").Range("E13") & ".xls", FileFormat:=xlOpenXMLWorkbookMacroEnabled

'ActiveWorkbook.Close
Application.DisplayAlerts = True

MsgBox "Saving Complete! Have a wonderful day~"

End Sub
```


It only saves in the student name list folder as 2022Adam_May_14052022 and under 2022 folder not in 2022 folder
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
It looks like the issue is with the way the file path is being constructed in the SaveAs method. Currently, the path is being constructed as follows:

VBA Code:
"\\uni\admin\Course Code\Lecturer Name\Semester\Class\STUDENT NAME LIST \2022" & Sheets("RESULT").Range("A5") & "_" & Sheets("RESULT").Range("E11") & "_" & Sheets("RESULT").Range("E13") & ".xls"

This creates a file path that includes the "STUDENT NAME LIST" folder and then the "2022" folder within that. To save the file in the "2022" folder directly, you should change the file path to:

VBA Code:
"\\uni\admin\Course Code\Lecturer Name\Semester\Class\2022\" & Sheets("RESULT").Range("A5") & "_" & Sheets("RESULT").Range("E11") & "_" & Sheets("RESULT").Range("E13") & ".xls"

This way the 2022 folder is the last folder in the file path. Also make sure that the folder exist or the file will not be saved in the desired location.
 
Upvote 1
Solution

Forum statistics

Threads
1,215,052
Messages
6,122,878
Members
449,097
Latest member
dbomb1414

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