LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Workbook does not Save from User Form

Try code like the following. Change the value of FName to the inital
filename.

Sub DoSaveAs()

Dim FName As Variant
Dim Ext As String
Dim N As Long
Dim FileFormat As XlFileFormat
Dim Ndx As Long
FName = ThisWorkbook.FullName
N = InStrRev(FName, ".")
Ext = Mid(FName, N + 1)
Select Case LCase(Ext)
Case "xls": Ndx = 1
Case "xlsm": Ndx = 2
Case "xlsx": Ndx = 3
Case "xlsb": Ndx = 4
End Select

FName = Application.GetSaveAsFilename(FName, _
"Excel Files (*.xls),*.xls," & _
"Excel Files (*.xlsm),*.xlsm," & _
"Excel Files (*.xlsx),*.xlsx," & _
"Excel Files (*.xlsb),*.xlsb", _
Ndx)

If FName = False Then
' user cancelled. get out.
Exit Sub
End If
N = InStrRev(FName, ".")
Ext = Mid(FName, N + 1)
Select Case LCase(Ext)
Case "xls": FileFormat = xlExcel8
Case "xlsx": FileFormat = xlWorkbookDefault
Case "xlsb": FileFormat = xlExcel12
Case "xlsm": FileFormat = xlOpenXMLWorkbookMacroEnabled
End Select
On Error Resume Next
If StrComp(FName, ThisWorkbook.FullName, vbTextCompare) < 0 Then
Kill FName
End If
On Error GoTo 0
ThisWorkbook.SaveAs Filename:=FName, FileFormat:=FileFormat

End Sub




Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]







On Thu, 31 Dec 2009 20:25:01 -0800, 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

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening Workbook from User Form Brian Excel Programming 10 December 25th 09 03:17 AM
Date field in user form & Loading a user form on opening workbook Balan Excel Programming 1 May 24th 08 03:40 PM
Using Button on User Form to save Data to specific Cell?? DarnTootn Excel Programming 2 May 13th 06 03:20 PM
VBA Question - Canceling a 'Save As' command from a user form Jake Marx[_3_] Excel Programming 2 May 6th 04 10:10 PM


All times are GMT +1. The time now is 12:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"