PC Review


Reply
Thread Tools Rate Thread

Code to select active workbook worksheet(s) in Excel 2007

 
 
RickLM
Guest
Posts: n/a
 
      22nd Dec 2009
Code to select active workbook worksheet(s) in Excel 2007

Need help I have limited experience in VBA and have been looking online and
in the Excel 2007 books I have but can not seem to locate/grasp what I need.
I require:

Module to run automatically when workbook is started.

Dropdown to provide selections: (1) workbook book to be used normally or (2)
a dropdown that will allow opening, editing, and closing of any/all of active
workbook worksheets.

Option (2) to remain available while workbook is open.

Workbook will have up to 30 sheets, maybe more.

Thanks in advance to the “group”
Rick

 
Reply With Quote
 
 
 
 
Ryan H
Guest
Posts: n/a
 
      22nd Dec 2009
First you will need to setup a Userform with a ComboBox in it. Then put this
in the workbooks Open_Event:

' this will call the userform to show
Private Sub Workbook_Open()
UserForm1.Show
End Sub

Then put this in the Userforms Intialize Event:

' this will load all the userforms in the workbook into the combobox
Private Sub UserForm_Initialize()

Dim wks As Worksheet

' load worksheet names into combobox
For Each wks In Worksheets
ComboBox1.AddItem wks.Name
Next wks

End Sub


Then put this in the ComboBox1 Change Event:

' when you change the combobox it will hide/unhide worksheets
Private Sub ComboBox1_Change()

Dim wks As Worksheet

Sheets(ComboBox1.Value).Visible = xlSheetVisible

For Each wks In Worksheets
If wks.Name <> ComboBox1.Value Then
wks.Visible = xlSheetVeryHidden
End If
Next wks

End Sub


Hope this helps! If so, let me know, click "YES" below.

--
Cheers,
Ryan


"RickLM" wrote:

> Code to select active workbook worksheet(s) in Excel 2007
>
> Need help I have limited experience in VBA and have been looking online and
> in the Excel 2007 books I have but can not seem to locate/grasp what I need.
> I require:
>
> Module to run automatically when workbook is started.
>
> Dropdown to provide selections: (1) workbook book to be used normally or (2)
> a dropdown that will allow opening, editing, and closing of any/all of active
> workbook worksheets.
>
> Option (2) to remain available while workbook is open.
>
> Workbook will have up to 30 sheets, maybe more.
>
> Thanks in advance to the “group”
> Rick
>

 
Reply With Quote
 
RickLM
Guest
Posts: n/a
 
      23rd Dec 2009
Ryan
Thx for help but as I said I have very little background in VBA (just enough
to get me into trouble, I’m 62 so this stuff is REAL new to me). I got
dropdown to open and select any single worksheet. Have following questions,
if you have time.
1) Select “All” so workbook runs normally
2) Select and show more than one worksheet but not all
2) Can’t edit selected worksheet without closing combobox
3) After selecting a worksheet can ComboBox be hidden and then unhidden for
selection of different worksheet?
3) If ComboBox is closed how to run it again without closing/reopening
workbook?

Ryan see by your profile you are in training… so hope this is not too
mundane for you
Thx again and Happy Holidays
Rick

--
RickLM


"Ryan H" wrote:

> First you will need to setup a Userform with a ComboBox in it. Then put this
> in the workbooks Open_Event:
>
> ' this will call the userform to show
> Private Sub Workbook_Open()
> UserForm1.Show
> End Sub
>
> Then put this in the Userforms Intialize Event:
>
> ' this will load all the userforms in the workbook into the combobox
> Private Sub UserForm_Initialize()
>
> Dim wks As Worksheet
>
> ' load worksheet names into combobox
> For Each wks In Worksheets
> ComboBox1.AddItem wks.Name
> Next wks
>
> End Sub
>
>
> Then put this in the ComboBox1 Change Event:
>
> ' when you change the combobox it will hide/unhide worksheets
> Private Sub ComboBox1_Change()
>
> Dim wks As Worksheet
>
> Sheets(ComboBox1.Value).Visible = xlSheetVisible
>
> For Each wks In Worksheets
> If wks.Name <> ComboBox1.Value Then
> wks.Visible = xlSheetVeryHidden
> End If
> Next wks
>
> End Sub
>
>
> Hope this helps! If so, let me know, click "YES" below.
>
> --
> Cheers,
> Ryan
>
>
> "RickLM" wrote:
>
> > Code to select active workbook worksheet(s) in Excel 2007
> >
> > Need help I have limited experience in VBA and have been looking online and
> > in the Excel 2007 books I have but can not seem to locate/grasp what I need.
> > I require:
> >
> > Module to run automatically when workbook is started.
> >
> > Dropdown to provide selections: (1) workbook book to be used normally or (2)
> > a dropdown that will allow opening, editing, and closing of any/all of active
> > workbook worksheets.
> >
> > Option (2) to remain available while workbook is open.
> >
> > Workbook will have up to 30 sheets, maybe more.
> >
> > Thanks in advance to the “group”
> > Rick
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unprotecting worksheet/workbook in Excel 2007 Steve Microsoft Excel Worksheet Functions 2 19th Sep 2008 04:00 AM
Unprotect workbook/worksheet Excel 2007 Steve Microsoft Excel Misc 0 17th Sep 2008 02:04 AM
save single excel worksheet out of workbook in excel 2007 =?Utf-8?B?cm9rYnJvc2NvcmU=?= Microsoft Excel Misc 2 13th Jul 2007 09:43 PM
In Excel 2007, custom ribbon tab fails with no active workbook =?Utf-8?B?QW5kcmV3IEI=?= Microsoft Excel Crashes 0 1st Mar 2007 08:47 PM
Re: VBA Code to copy a worksheet to another Excel Workbook Dave Peterson Microsoft Excel Programming 0 9th Nov 2004 12:54 AM


Features
 

Advertising
 

Newsgroups
 


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