VBA to Save Workbook As

tomexcel1

New Member
Joined
Feb 22, 2018
Messages
47
Hi All

I've been using the below macro for a bit to save a file when a commend button is pressed in a specific location with a randomised password. Its started to fail now on the line highlighted in bold. Can anyone see why this would happen? I just cant work it out.

Thanks
Tom

Code:
Private Sub CommandButton3_Click()
If MsgBox("File will be saved to ""FOLDER NAME"" Shared Drive" & vbNewLine & "" & vbNewLine & "Do you wish to continue?", vbYesNo + vbInformation, "Save File?") = vbNo Then Exit Sub


Application.ScreenUpdating = False
Application.DisplayAlerts = False


Set wb1 = ActiveWorkbook
FinFilePath = "\\Folder Name\Folder name\Folder name\folder name\folder name\folder name\folder name\"
FinFileName = Sheet1.Range("R27").Value & " - " & Format(Now, "dd.mm.yy")
FinExtStr = "." & LCase(Right(wb1.Name, Len(wb1.Name) - InStrRev(wb1.Name, ".", , 1)))
[B]ActiveWorkbook.SaveAs FinFilePath & FinFileName & FinExtStr, , "", Int((9999 - 1000 + 1) * Rnd + 1000)[/B]


Application.ScreenUpdating = True
Application.DisplayAlerts = True


MsgBox "File Saved!", vbOKOnly + vbInformation, "Complete"


End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
What is the exact error message it is giving you?
Did you confirm it is building a valid file path/name, one that you have access to that drive?
It should be easy enough to confirm with a message box, i.e.
Code:
[B]MsgBox[/B] [B]FinFilePath & FinFileName & FinExtStr[/B]
 
Upvote 0
Hi Joe

The Error is:

Run-Time Error '1004':
Document not Saved

I've ran the msgbox in the immediate window and the path and file name that comes back is fine. Could it be the path/name is two long? its 245 characters including spaces

Thanks
Tom
 
Upvote 0
You said it used to work in the past, but does not now anymore.
So, what has changed since then?
New computer? New file paths? Upgrade of Office/Windows? Anything else?
 
Upvote 0

Forum statistics

Threads
1,223,967
Messages
6,175,673
Members
452,666
Latest member
AllexDee

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