Save As File Name & File Path & Date Time & .CVS FileFormat:=6

Shiseiji

Board Regular
Joined
Oct 23, 2009
Messages
214
Office Version
  1. 2019
Platform
  1. Windows
Hello to the patient guru's of Mr. Excel.
The file is not being saved. I'm getting the error message "CEDR_File_for_AtHoc_09-21-2023 948AM.csv' cannot be accessed. The file may be corrupted, located on a server that is not responding, or read-only."

Ideas?
PS was just "upgraded" to Office LTSC on corporate Win 10. Not yet listed as Office Version an option

Your time and assistance is deeply appreciated.

Ron

VBA Code:
Sub SaveFinalAsCVS3_m()
'https://www.mrexcel.com/board/threads/macro-needed-to-save-workbook-as-xlsx-and-remove-macros.1035215/
 '20230919
'
      Dim FileD     As String
      Dim FileP     As String 'file path
      Dim FileN     As String ' file name
      Dim FileF     As String  'File Format
      Dim ThisWb    As Workbook
'---
      Set ThisWb = ActiveWorkbook
      With ThisWb
'---
      FileP = Range("SaveFile").Value
      FileN = "CEDR_File_for_AtHoc_"
      FileD = Format(Now, "mm-dd-yyyy  hmmAM/PM")

'---
     ThisWb.SaveAs FileP & FileN & FileD & ".csv", FileFormat:=6
'---
    ThisWb.Saved = True
'
End With 'ThisWb
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Are you sure that you have a valid path?

What happens if you temporarily replace the "SaveAs" line with this:
VBA Code:
MsgBox FileP & FileN & FileD & ".csv"
What does it return back to the screen?
Does it look like a valid path and file name?
Are you able to manually save a file to that location?
 
Upvote 0
2023-09-21_10-46-52.png

And then:
2023-09-21_10-51-50.png


Yes path is valid, I haven't changed it in months.
Yes, I can save the .xlsm file to the location and I can save as the .csv to the location.

Ron
 
Upvote 0
Which line of code returns that 424 error?
Were you able to manually save a file to that location and with that name?

Also, you can get rid of your "With" and "End With" lines since you aren't even using them.
 
Upvote 0
I realized after the message is rendered, the file hasn't actually saved. The object error return a specific line.
 
Upvote 0
Try looping through your code one line at a time using the F8 key and see when the error occurs.
 
Upvote 0
Try looping through your code one line at a time using the F8 key and see when the error occurs.
Thanks much for seeing what you can do to help. I've used this for years with the file name & type in the save as line, but I need to pass this on to others and they don't code at all. Trying to get Excel to use the string in the named ranges for the save as.

After flashing the message box shown as image 1 in my earlier post, the title bar renders the.cvs file name. Stepping through the next message box is "Method 'SaveAs' of object'_Workbook failed and the title bar reverts to showing the .xlsm file name.

Ron
 
Upvote 0
I simplified your code to this, and it seemed to work for me:
VBA Code:
Sub SaveFinalAsCVS3_m()
'https://www.mrexcel.com/board/threads/macro-needed-to-save-workbook-as-xlsx-and-remove-macros.1035215/
 '20230919
'
      Dim FileD     As String
      Dim FileP     As String 'file path
      Dim FileN     As String ' file name

'---
      FileP = Range("SaveFile").Value
      FileN = "CEDR_File_for_AtHoc_"
      FileD = Format(Now, "mm-dd-yyyy  hmmAM/PM")

'---
     ActiveWorkbook.SaveAs FileP & FileN & FileD & ".csv", FileFormat:=6

End Sub

Do you have any VBA code in the "ThisWorkbook" module of this workbook?
Maybe you have some other automated code interfering with this.
 
Upvote 0
Solution
Verified, no workbook level code. Interesting that the object reference statement is the problem. I've used code similar to the code you provided for a long time, but never trying to set the date and wanted to see if would work. Apparently it will but not with the workbook set as the object. Why that is will take someone with real programming skills above my hack it together level. As long as the range reference works the goal is achieved.

Appreciate your time and effort, it's very much appreciated. I tried to make the subject very descriptive to try and help others in the future, pass it forward.

Ron
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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