Saving to a Fpath and Fname not working

Mr Denove

Active Member
Joined
Jun 8, 2007
Messages
446
Dear All,

The folder path will change each month, the filename changes week on week. Im trying to use the data from the cell on the Control sheet to deal with the name changes and save to a specific folder with the new file name. But alas to no avail.
Can someone please advise why it wont work?

Code:
Sub Saving_Closing_File()
Dim sPath As String

'ThisWorkbook.Sheets("Control").Range("F23").Value = "File is saving...."
Application.ScreenUpdating = False
     
Application.DisplayAlerts = False

Application.DisplayStatusBar = False

ActiveSheet.DisplayPageBreaks = False

Application.CutCopyMode = False

Application.Calculation = xlCalculationManual

Application.EnableEvents = False

'ThisWorkbook.Save
Dim FPath As String
Dim FName As String
FPath = Sheets("Control").Range("C80")
FName = Sheets("Control").Range("C81").Text

If FPath = vbNullString Then Exit Sub
Filename1 = InputBox("DATE FORMAT...DD.MM.YY", "Filename")
Filename2 = "BAU Extract " & Filename1
If StrPtr(Filename1) = 0 Then
        MsgBox "You pressed Cancel!"
        
        GoTo Error
    Else
        If Filename1 = "" Then
      
      End If

Sheets("Control").Range("C79") = Filename1
FP = Sheets("Control").Range("C80")
Dim Wk As Workbook

Set Wk = WorkBooks.Add
Application.DisplayAlerts = False

Dim arrSheets As Variant, sht As Variant
With Wk
ThisWorkbook.Sheets(Array("Data")).Copy Before:=Wk.Sheets(1)

End With

sarray = Array("Data")
Application.DisplayAlerts = False
For Each sht In Wk.Worksheets
    If IsError(Application.Match(sht.Name, sarray, 0)) Then
        sht.Delete
    End If
Next sht

'*************************
'SAVE THE BAU EXTRACT FILE
'*************************
Wk.Activate
   ActiveWorkbook.SaveAs FileName:=FPath & "\" & Filename2, FileFormat:=xlCSV, _
            ReadOnlyRecommended:=False, _
            CreateBackup:=False

ThisWorkbook.Activate
ThisWorkbook.Sheets("Control").Range("J11") = "Extract Saved"
ThisWorkbook.Sheets("Control").Range("J6").ClearContents
ThisWorkbook.Sheets("Control").Range("J9").ClearContents

ThisWorkbook.Sheets("Control").Range("F23").ClearContents
Wk.Close
Application.ScreenUpdating = False


Error:
Application.ScreenUpdating = True
     
Application.DisplayAlerts = True

Application.DisplayStatusBar = True

ActiveSheet.DisplayPageBreaks = False

Application.CutCopyMode = True

Application.EnableEvents = True

Application.Calculation = xlCalculationAutomatic

End If


End Sub

As always, many thanks in advance.
Stuart
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
What exactly is happening?
 
Upvote 0
What are the values of FPath and Filename2 at that point? Also, you can leave out the last two arguments as they won't apply to a CSV file.
 
Upvote 0
HI Rory

FPath is the folder path taken from concatenating in a cell to add the new month name and year when appropriate.
The Filename2 is similar its the full filename.

Can you please confirm which two arguments you are referring to?

Stuart
 
Upvote 0
I assume Rory means leave these two out:-

ReadOnlyRecommended:=False, _
CreateBackup:=False


Also

When Rory asks what the values of FPath and Filename2 are he means stop the code and note down what the values are eg "C:\squidge\splat" and "funkymonkeysrus"
 
Last edited:
Upvote 0
The two values are
Filename2 = "BAU Extract 15.11.17"
FPath = "\\Internal links redacted for public display\Prep Data Nov 2017"

the file is being saved as a csv.

Thanks, Stuart
 
Upvote 0
Your code works for me (not your path).

I don't like this "\\Internal......"

Shouldn't there be a drive letter? Something like ""C:\Users"
 
Upvote 0
The issue could be the dots - try adding the extension:

Code:
ActiveWorkbook.SaveAs FileName:=FPath & "\" & Filename2 & ".csv", FileFormat:=xlCSV
 
Upvote 0
I assumed that might be the case Rory (definitely bad form to have the date in the format with dots) but it worked for me.
 
Upvote 0

Forum statistics

Threads
1,223,970
Messages
6,175,710
Members
452,667
Latest member
vanessavalentino83

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