Workbook does not Save from User Form
Hi Brian,
I cannot see anywhere in your code where you have assigned anything to the
variable FileToSave.
Therefore it will always be false if it has not been declared or has been
declared as a variant. If declared as anything else other than variant or
boolean then I believe it will return an error.
The following example tests whether or not a workbook has unsaved changes.
If Workbooks("Book1.xlsm").Saved Then
MsgBox "Workbook has NO unsaved changes"
Else
MsgBox "Workbook contains unsaved changes"
End If
You can assign the workbook name to a variable and use it in lieu of the
actual name as per the following.
FileToSave = "Book1.xlsm"
If Workbooks(FileToSave).Saved Then
You can also use ThisWorkbook as per the following
If ThisWorkbook.Saved Then
--
Regards,
OssieMac
"Brian" wrote:
I pasted this code in my User Form to assign the Name & Save a Workbook as
varibles from different Text Boxes. For some reason it assigns the name
correctly, but when you click on the save in the Save As Dialog box, only the
Error Message pops up and the Workbookbook does not save.
What am I missing?
'Save Engineering Spec 11 Control Button
Private Sub Save_Eng_Spec_11_Click()
Dim strFile As String
Dim bk As Workbook
strFile = "SPEC " & TEO_No_1.Value _
& Space(1) & CLLI_Code_1.Value _
& Space(1) & CES_No_1.Value _
& Space(1) & TEO_Appx_No_2.Value
strFile = Application.GetSaveAsFilename( _
InitialFileName:=strFile, _
fileFilter:="Excel Files (*.xls;*.xlsm;*.xlst), " & _
"*.xls;*.xlsm;*.xlst")
If FileToSave = False Then
MsgBox "The Save Method Failed, Eng Spec was not Saved", , "C.E.S."
Exit Sub
End If
End Sub
|