Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 20th, 2012, 11:19 PM
Authorized User
 
Join Date: Jan 2012
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to close a file

I have 3 command buttons on a userform. When the user selects command button 3, for example, it will perform the following code below assigned to it.

Code:
Private Sub CommandButton3_Click()
 Workbooks.Open Filename:="C:\........\........\Documents\filename.xlsm"
End Sub
Once this file opens, it displays another userform. However, the first userform is still opened in the background. How do I close that userform before it opens the new one?

I tried to include this code directly after the one above but it didn't work.
Code:
Workbooks("C:\....\.....\Documents\filename.xlsm").Close
I even tried: Workbooks("filename.xlsm").close

Didn't work. Both instances still left it opened in the background.

Thanks.
 
Old July 2nd, 2012, 03:15 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

If you want to Hide the userform try

Me.Visible = False

OTH if you want to unload it completely use

Unload Me

It should be
Code:
Private Sub CommandButton3_Click()
 Workbooks.Open Filename:="C:\........\........\Documents\filename.xlsm"
 Unload Me
End Sub
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to close and save excel file . honey26 Excel VBA 2 November 17th, 2011 03:47 AM
Close Adobe after printing PDF file BoardBabe Access VBA 5 October 11th, 2011 05:26 PM
Browser close when screen saver close Rehanrana Pro VB 6 1 April 7th, 2008 03:09 AM
file names (close enough) tontos Classic ASP Basics 1 July 25th, 2004 08:14 PM
Open & Close Excel file in the background mikezhang Classic ASP Professional 0 March 17th, 2004 08:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.