Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Closing workbooks w/o closing Excel | Excel Discussion (Misc queries) | |||
Closing Excel | Excel Discussion (Misc queries) | |||
Closing Excel | New Users to Excel | |||
Userform won't show after closing another file | Excel Discussion (Misc queries) | |||
Re-show userform after closing file - code help | Excel Discussion (Misc queries) |