Worksheet.activate

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have the following VBA Macro:
fname = Application.GetOpenFilename
Workbooks.Open filename:=fname
fname = Application.GetOpenFilename
Set wb = Workbooks.Open(filename:=fname)
fname has 12 worksheets. It is possible to activate any of them with an
inputbox ?
Thanks,
 
One way:

Const sPROMPT As String = "Which Sheet (% max)?"
Dim wb As Workbook
Dim vResult As Variant
Dim nMax As Long
Dim fname As String
fname = Application.GetOpenFilename
Workbooks.Open Filename:=fname
fname = Application.GetOpenFilename
Set wb = Workbooks.Open(Filename:=fname)
nMax = wb.Worksheets.Count
Do
vResult = Application.InputBox( _
Prompt:=Application.Substitute(sPROMPT, "%", nMax), _
Title:="Open " & fname, _
Type:=1, _
Default:=1)
If vResult = False Then Exit Do 'User cancelled
Loop Until vResult >= 1 And vResult <= nMax
If IsNumeric(vResult) Then If vResult > 0 Then _
wb.Worksheets(vResult).Activate
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Activating Workbooks 2
Listbox in VBA 1
Open files from List 9
Out of Range 5
Workbook.activate 1
Sub out of range 1
VBA Formula Help 6
Copy Cells 2

Back
Top