You have several things to do if you want to prevent errors. To see which line is causing the error, in the VBE, press F8 in the routine until you find the error line.
I considered a few problems here. Of course it will still error if C36 contains an illegal filename. You would need an API routine to check for a valid filename string. Same error occurs for illegal folder names in C27.
Private Sub Button989_Click()
Dim MyDesktop As String, r As Range, r2 As Range
Dim f As String
With Worksheets("Sheet8")
Set r = .Range("C36")
Set r2 = .Range("C27")
If IsEmpty(r) Then Exit Sub
If r2.Value = "Desktop" Then
MyDesktop = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator
f = MyDesktop & r.Value & ".xls"
If ActiveWorkbook.FullName = f Then
ActiveWorkbook.Save
Exit Sub
End If
If Dir(f) <> "" Then Kill f
ActiveWorkbook.SaveAs Filename:=f
End If
If r2.Value = "C:\Sample Spec Sheets" Then
If Dir("C:\Sample Spec Sheets", vbDirectory) = "" Then MkDir "C:\Sample Spec Sheets"
f = "C:\Sample Spec Sheets\" & r.Value & ".xls"
If ActiveWorkbook.FullName = f Then
ActiveWorkbook.Save
Exit Sub
End If
If Dir(f) <> "" Then Kill f
ActiveWorkbook.SaveAs Filename:=f
End If
End With
End Sub
Bookmarks