Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Help with closing a UserForm

Unload Userform1

Is closing the userform Eric


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Eric" wrote in message ...
I have a userform that I bring up that have two userforms
associated with it. What I want to do is close the
userform when a button is pushed. I know to bring up a
userform is UserForm1.Show but how do I close it using
VBA? My Code below...

Sub Macro1()

Application.ScreenUpdating = False
Documents.Add

x = 1

'Loading bitmaps to Word and checking if any were
skipped
Do Until y = 3
If Len(Dir("\\files-2k1\d35058$\cptl" & x
& ".bmp")) 0 Then
Selection.InlineShapes.AddPicture FileName:= _
"\\files-2k1\d35058$\cptl" & x & ".bmp",
LinkToFile:=False, SaveWithDocument:= _
True
x = x + 1
y = 0
ElseIf Len(Dir("\\files-2k1\d35058$\cptl" & x
& ".bmp")) = 0 Then
y = y + 1
x = x + 1
Else
Exit Do
End If
Loop

UserForm1.Show
End Sub

First button on Userform1....

Private Sub CommandButton1_Click()

Dim fldrname1 As String
Dim fname As String

'UserForm1.

fldrname1 = InputBox("What is the name of the
plant?", "Folder Name Notification")

If fldrname1 = "" Then
Do
fldrname1 = InputBox("No name was found. You must
type in a file name.", "File Name Alert")
Loop Until fldrname1 < ""
End If

If Len(Dir("\\files-2k1\Eng\QA\ThirdPartyAudits\" &
fldrname1 & "\")) = 0 Then
MkDir ("\\files-2k1\Eng\QA\ThirdPartyAudits\" &
fldrname1 & "\")
End If

fname = InputBox("What is the file name you would
like?", "File Name Notification")

Do
If fname = "" Then
fname = InputBox("No name was found. You must type
in a file name.", "File Name Alert")
End If
Loop Until fname < ""

Application.ScreenUpdating = True

Do
If Len(Dir("\\files-2k1\Eng\QA\ThirdPartyAudits\" &
fldrname1 & "\" & fname & ".doc")) 0 Then
fname = InputBox("File already exists. Please
enter another file name.", _
"File Name Alert")
If fname = "" Then
MsgBox "No name was found or you hit Cancel.
Closing Word w/o saving..."
Application.Quit (False)
End If
Else
Exit Do
End If
Loop Until Len(Dir("\\files-2k1\Eng\QA\ThirdPartyAudits\"
& fldrname1 & "\" & fname & ".doc")) = 0

ActiveDocument.SaveAs ("\\files-2k1
\Eng\QA\ThirdPartyAudits\" & fldrname1 & "\" & fname)

If Len(Dir("\\files-2k1\d35058$\*.bmp")) < 0 Then
Kill "\\files-2k1\d35058$\*.bmp"

ActiveDocument.Close 'Closes the document

ErrorHandler_Exit:
Exit Sub

ErrorHandler:
Select Case Err
Case 53
MsgBox "No file found. Exiting 'Add Audit
Report' procedure."
GoTo ErrorHandler_Exit
Case Else
MsgBox Err.Number & " " & Err.Description
GoTo ErrorHandler_Exit
End Select

End Sub

Second button on UserForm1...

Private Sub CommandButton2_Click()

Dim fname As String
Dim fldrname1 As String

'UserForm1.
fname = InputBox("What is the file name?", "File Name
Notification")
fldrname1 = InputBox("What is the folder
name?", "Folder Name Notification")
If fname = "" Or fldrname1 = "" Then Exit Sub
If Len(Dir("\\files-2k1\Eng\QA\Individual
Folder\Martin\CARs\" & fldrname1 & "\")) = 0 Then
MkDir ("\\files-2k1\Eng\QA\Individual
Folder\Martin\CARs\" & fldrname1 & "\")
End If
Recheck:
If Len(Dir("\\files-2k1\Eng\QA\Individual
Folder\Martin\CARs\" & fldrname1 & "\" & fname)) < 0 Then
fname = InputBox("File already exists. Please type
in another file name.", "File Name Alert")
GoSub Recheck
End If
ActiveDocument.SaveAs ("\\files-2k1\Eng\QA\Individual
Folder\Martin\CARs\" & fldrname1 & "\" & fname)
MsgBox "File saved to J:\QA\Individual
Folder\Martin\CARs\" & fldrname1 & "\" & fname & ".doc"
ActiveDocument.Close (False)
If Len(Dir("\\files-2k1\d35058$\*.bmp")) < 0 Then
Kill "\\files-2k1\d35058$\*.bmp"

End Sub



Reply
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
Closing workbooks w/o closing Excel Barb in MD Excel Discussion (Misc queries) 3 February 15th 10 06:42 PM
Closing Excel chip1in Excel Discussion (Misc queries) 2 August 31st 09 04:49 PM
Closing Excel RVarner New Users to Excel 1 May 24th 09 04:06 PM
Userform won't show after closing another file Gerry O Excel Discussion (Misc queries) 8 September 7th 07 03:51 PM
Re-show userform after closing file - code help Gerry O Excel Discussion (Misc queries) 3 September 4th 07 10:52 PM


All times are GMT +1. The time now is 01:43 AM.

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

About Us

"It's about Microsoft Excel"