Form button operation

feistdj
03-30-2003, 05:14 PM
I have a button on a form that opens a save as dialog box in an Excel addin. Once the file is saved the file name is set to the text property in a text box on the form but the form closes as soon as the file is saved. I want the form to remain open after the file is saved. Is there a button property or code that will keep the form open?

shep
03-30-2003, 07:41 PM
Post your code for the command button, without it I can't really see where it's going wrong.

eric

feistdj
03-30-2003, 09:46 PM
I just cut and pasted this from my code so I'll explain. The button opens a template Excel file and changes its extension when it is saved. This program had to be coded without the use of OCX or ActiveX controls (for system compatbility reasons) that is why I didn't use the common dialog box method.

vbcode

Private Sub project_new_Click()
ERH_PushStack_TSB ("frmdlgFiles.project_new_Click")

Dim NewBook As Workbook
Dim fName As String

Set NewBook = Application.Workbooks.Add("C:\defproj.cs2")

fName = Application.GetSaveAsFilename

If Right(fName, 4) <> ".cs2" Then
fName = fName & ".cs2"


End If

NewBook.SaveAs FileName:=fName


project_edit.Text = fName


ThisWorkbook.Saved = False

End

/vbcode

shep
03-31-2003, 01:27 AM
After my edits it recreates defproj.cs2 as fName.cs2 and then opens it for editing. Is this what your looking for?

Private Sub project_new_Click()
'ERH_PushStack_TSB ("frmdlgFiles.project_new_Click" )
'I'm guessing it's your own function?

Dim NewBook As Workbook
Dim fName As String

Set NewBook = Application.Workbooks.Add("C:\defproj.cs2" )

fName = Application.GetSaveAsFilename

If Right(fName, 4) <> ".cs2" Then
fName = fName & "cs2"
'fName = fName & ".cs2"
'The dot before cs2 creates a double dot in the filename

End If

NewBook.SaveAs FileName:=fName


'project_edit.Text = fName
'What is this line all about? Is it defined in the above function


ThisWorkbook.Saved = False

End Sub
'End
'I changed this to End Sub


eric

feistdj
03-31-2003, 09:26 PM
The code already did what I wanted it to but you did provide the solution. I put End before End sub and that caused the problem.
(the text box was defined in a different module)
Thanks for the help.

Final code



Private Sub project_new_Click()
ERH_PushStack_TSB ("frmdlgFiles.project_new_Click")

Dim NewBook As Workbook
Dim fName As String
Set NewBook = Application.Workbooks.Add("C:\defproj.cs2")
fName = Application.GetSaveAsFilename

If Right(fName, 4) <> ".cs2" Then
fName = fName & ".cs2"

End If

NewBook.SaveAs FileName:=fName

project_edit.Text = fName

ThisWorkbook.Saved = False

Proc_exit:
ERH_PopStack_TSB
Exit Sub

Proc_err:
ERH_Handler_TSB
Resume Proc_exit


End Sub

shep
03-31-2003, 11:04 PM
No problem, glad I could help.

eric

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum