tomexcel1

New Member
Joined
Feb 22, 2018
Messages
45
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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,910
Office Version
  1. 365
Platform
  1. Windows
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]
 

tomexcel1

New Member
Joined
Feb 22, 2018
Messages
45
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
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,910
Office Version
  1. 365
Platform
  1. Windows
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?
 

Watch MrExcel Video

Forum statistics

Threads
1,129,313
Messages
5,635,499
Members
416,860
Latest member
coen078

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
Top