VBA To Save Files (1 Viewer)

AlaminK

New member
Local time
Tomorrow, 00:29
Joined
Apr 2, 2023
Messages
15
While saving a file, it picks up the specific folder path. After adding a path in the VBA it opened, and then I have to locate it in the folders. Please, help.
 
Last edited:

June7

AWF VIP
Local time
Today, 10:29
Joined
Mar 9, 2014
Messages
5,473
Please post code between CODE tags to retain indentation and readability.

You are not including complete file path in the ouputFileName. Instead of ChDir (which apparently has no relevance), concatenate this path to ouputFileName.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:29
Joined
May 7, 2009
Messages
19,245
as suggested in post#2, add the outputpath:

Code:
Sub SUBSaveNewStatement()
'
' Newstatement1 Macro
' copy and save to new file for a new account statement.
'

'
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False

'Set the output path and file name
outputPath = "C:\Users\bdumitrascu\OneDrive - PTC\Documents\Account statements"
CustomerName = Range("B2").Value
CustomerNumber = Range("C2").Value
CustomerSite = Range("E2").Value
outputFileName = CustomerName & " - " & CustomerNumber & " - " & CustomerSite & " - Updated Statement - " & Format(Date, "dd-MMM-yyyy") & ".xlsx"

ActiveWorkbook.SaveAs filename:=outputPath & "\" & outputFileName, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
End Sub

Sub SvMe()
'Saves filename

Dim newFile As String, outputFileName As String
dim outputpath As String

'Change the date format to whatever you'd like, but make sure it's in quotes
outputpath = "C:\Users\bdumitrascu\OneDrive - PTC\Documents\Account statements"
outputFileName = CustomerName & " - " & CustomerNumber & " - " & CustomerSite & " - Updated Statement - " & Format(Date, "dd-MMM-yyyy") & ".xlsx"
' Change directory to suit your PC, including USER NAME
ChDir _
"C:\Users\bdumitrascu\OneDrive - PTC\Documents\Account statements"
ActiveWorkbook.SaveAs filename:= outputpath & "\" & outputFileName

End Sub
 

Users who are viewing this thread

Top Bottom