PC Review


Reply
Thread Tools Rate Thread

Allow user to choose worksheet from newly opened file

 
 
Chris Lewis
Guest
Posts: n/a
 
      3rd Oct 2006
I have written a macro that performs the same set of commands to a worksheet
for a set of data of a given format.

this data is supplied to me from various sources but is always of the same
format. I want the macro in one excel file to prompt for which file to open
(which I have done using Application.GetOpenFilename) and then prompt the
user for which worksheet should be made active. The names of the sheets are
indicative of what they contain.

So I guess after saying open test.xls I want the user prompted with a list
of the worksheets available in test.xls and allow them to select which
should be made active for the macro to perform its duties.

Any ideas?

Thanks

--
Chris Lewis


 
Reply With Quote
 
 
 
 
Nigel
Guest
Posts: n/a
 
      3rd Oct 2006
I created a userform, with a combobox and commandbutton, the form is opened
after the GetOpenFileName dialog ends with

UserForm1.Show

In the userform code, the combobox is filled with the names of all sheets in
the activeworkbook, if a valid name is chosen by the user the selected sheet
is activated,. The command closes the userform. Your code could run after
this.

Private Sub ComboBox1_Change()
If ComboBox1.ListIndex >= 0 Then
Sheets(ComboBox1.Value).Activate
End If
End Sub

Private Sub CommandButton1_Click()
Unload Me
End Sub

Private Sub UserForm_Initialize()
Dim Ws As Worksheet
For Each Ws In ActiveWorkbook.Worksheets
ComboBox1.AddItem Ws.Name
Next
End Sub

--
Cheers
Nigel



"Chris Lewis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have written a macro that performs the same set of commands to a
>worksheet for a set of data of a given format.
>
> this data is supplied to me from various sources but is always of the same
> format. I want the macro in one excel file to prompt for which file to
> open (which I have done using Application.GetOpenFilename) and then prompt
> the user for which worksheet should be made active. The names of the
> sheets are indicative of what they contain.
>
> So I guess after saying open test.xls I want the user prompted with a
> list of the worksheets available in test.xls and allow them to select
> which should be made active for the macro to perform its duties.
>
> Any ideas?
>
> Thanks
>
> --
> Chris Lewis
>



 
Reply With Quote
 
Chris Lewis
Guest
Posts: n/a
 
      3rd Oct 2006

"Nigel" <nigel-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I created a userform, with a combobox and commandbutton, the form is
>opened after the GetOpenFileName dialog ends with
>
> UserForm1.Show
>
> In the userform code, the combobox is filled with the names of all sheets
> in the activeworkbook, if a valid name is chosen by the user the selected
> sheet is activated,. The command closes the userform. Your code could
> run after this.
>
> Private Sub ComboBox1_Change()
> If ComboBox1.ListIndex >= 0 Then
> Sheets(ComboBox1.Value).Activate
> End If
> End Sub
>
> Private Sub CommandButton1_Click()
> Unload Me
> End Sub
>
> Private Sub UserForm_Initialize()
> Dim Ws As Worksheet
> For Each Ws In ActiveWorkbook.Worksheets
> ComboBox1.AddItem Ws.Name
> Next
> End Sub
>
> --
> Cheers
> Nigel
>
>


It werks!! Ta muchly!

--
Chris Lewis


 
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
Adding newly created user defined fields to map for CSV file impor Technicater Microsoft Outlook Discussion 2 15th Mar 2008 02:32 PM
Set focus on newly opened MDB/MDE =?Utf-8?B?Q2hpYmJ5?= Microsoft Access VBA Modules 0 18th Mar 2007 01:54 AM
Make name assigned to newly added worksheet persist when file save =?Utf-8?B?TGFtb250?= Microsoft Excel Programming 2 2nd Feb 2007 09:33 PM
Close file and run macro from newly opened file =?Utf-8?B?UHJhZGlwIEphaW4=?= Microsoft Excel Programming 1 23rd Apr 2005 11:39 PM
control on a user form to choose a worksheet dovrox Microsoft Excel Misc 1 11th May 2004 10:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:11 AM.