I am trying to run some VBA (Not my strongpoint), which when i had i on a form control button worked fine! But once i flipped to ActiveX, I am struggling to get it working.
Can anyone see the issue? It fails at highlighted line.
If there is a cleaner way of doing the same I would be happy to hear any suggestions too.
Matt
Can anyone see the issue? It fails at highlighted line.
If there is a cleaner way of doing the same I would be happy to hear any suggestions too.
Private Sub MyButton_Click()
'Saves filename as value of A1 plus the current date plus changes all INDIRECT refrences to static data
Dim newFile As String, fName As String
fName = Range("A1").Value
newFile = fName & " " & Format$(Date, "dd-mm-yyyy")
'turn off alerts for SAVEAS
Application.DisplayAlerts = False
'SAVE file
ChDir _
"C:\Users\Public\Documents"
ActiveWorkbook.SaveAs Filename:=newFile
'turn alerts back on
Application.DisplayAlerts = True
'select copy from data
Sheets("ALN").Select
Range("A1:Q52").Select (Note: This was origonally cells.select)
Selection.Copy
'select copy to array
Sheets(Array("ALN", "CAS", "CWO", "DEI", "EON", "GMC", "HBM", "HDM", "HPU", "IDD", "KOE", _
"LAE", "LYP", "MEN", "MLP", "PAC", "PFR", "POE", "RUL", "SAR", "SCG", "SON", "TRF", "VAT", _
"VEL", "WAO", "WGV")).Select
'paste special values
Sheets("ALN").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'back to front page
Sheets("ScoreCard").Select
'delete button on new file
Dim Btn As Object
ActiveSheet.Shapes("MyButton").Delete
End Sub
Thanks,'Saves filename as value of A1 plus the current date plus changes all INDIRECT refrences to static data
Dim newFile As String, fName As String
fName = Range("A1").Value
newFile = fName & " " & Format$(Date, "dd-mm-yyyy")
'turn off alerts for SAVEAS
Application.DisplayAlerts = False
'SAVE file
ChDir _
"C:\Users\Public\Documents"
ActiveWorkbook.SaveAs Filename:=newFile
'turn alerts back on
Application.DisplayAlerts = True
'select copy from data
Sheets("ALN").Select
Range("A1:Q52").Select (Note: This was origonally cells.select)
Selection.Copy
'select copy to array
Sheets(Array("ALN", "CAS", "CWO", "DEI", "EON", "GMC", "HBM", "HDM", "HPU", "IDD", "KOE", _
"LAE", "LYP", "MEN", "MLP", "PAC", "PFR", "POE", "RUL", "SAR", "SCG", "SON", "TRF", "VAT", _
"VEL", "WAO", "WGV")).Select
'paste special values
Sheets("ALN").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'back to front page
Sheets("ScoreCard").Select
'delete button on new file
Dim Btn As Object
ActiveSheet.Shapes("MyButton").Delete
End Sub
Matt