VBA Error 400 with Button

orsettgreenboy

New Member
Joined
Sep 20, 2011
Messages
22
Hi there :)

I'm getting an error when running a macro that says "Microsoft Visual Basic for Appli... :crash: 400."

The macro I'm running should generate the next sequential number and then the save the file into a shared folder on our network with a new file name based on certain cell criteria and also send me an email with a copy of the file. I have altered the email address in the code below for confidentiality reasons only.

There is a hidden list & some hidden & some locked cells (but unhiding these don't seem to make any difference). These are protected by a sheet password.


This has worked earlier (i can't see what has changed) and then today it only worked the first time i used the macro, and now it doesn't work at all giving the above mentioned error.

There is nothing highlighted in debug.

The VB Code is as below

Sub SvMe() 'Generate next number to B5 and Save filename as value of B5 plus the current date etc etc
Sheet1.Unprotect Password:="Monkey"
Range("B5") = Range("B5") + 1
Sheet1.Protect Password:="Monkey"
Dim newFile As String, fName As String, fName3 As Integer, fName2 As String, fName4 As String, fName5 As String, fName6 As String
' Don't use "/" in date, invalid syntax
fName = Range("G3").Text
fName2 = Range("G4").Text
fName3 = Range("B5").Value
fName4 = Range("G17").Text
fName5 = Range("I17").Text
fName6 = Range("G15").Text
newFile = fName & " " & Format(Now, "yyyymmdd") & " " & fName2 & fName3 & fName4 & " " & fName5 & " " & fName6
' Change directory to suit
ChDir _
"P:\Quality\Non Conformances" 'YOU MUST Change USER NAME to suit
ActiveWorkbook.SaveAs Filename:=newFile
Dim wb As Workbook
Dim I As Long
Set wb = ActiveWorkbook
If Val(Application.Version) >= 12 Then
If wb.FileFormat = 51 And wb.HasVBProject = True Then
MsgBox "There is VBA code in this xlsx file, there will" & vbNewLine & _
"be no VBA code in the file you send. Save the" & vbNewLine & _
"file first as xlsm and then try the macro again.", vbInformation
Exit Sub
End If
End If
On Error Resume Next
For I = 1 To 3
wb.SendMail "xx@xxxx.co.uk", _
"Non Conformance"
If Err.Number = 0 Then Exit For
Next I
On Error GoTo 0
End Sub


Really appreciate any help you can offer, but please note i'm a newbie to VB and the code above was compiled from various internet sources (so as it is not my own work so I can't really understand what each part is doing where the error might be)

Thanks :)
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,224,600
Messages
6,179,833
Members
452,947
Latest member
Gerry_F

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