Code I have now asks the user to select a workbook, Open the workbook selected, and then ask the user to select a number of the worksheet to use for later calculations. The problem I forsee is the user has to know the number of the worksheet. I would much rather have the user be able to click on a worksheet tab or be given an option of the the worksheet names available in the opened workbook.
The current code converts the sheet number entered to a sheet name, but like I said, the current code assumes the user knows the sheet number desired, which could present a problem if that sheet number is not known by the user.
This is the code I have come up with thus far:
The current code converts the sheet number entered to a sheet name, but like I said, the current code assumes the user knows the sheet number desired, which could present a problem if that sheet number is not known by the user.
This is the code I have come up with thus far:
VBA Code:
Sub ChooseWorkbookAndSheetNumberToUse()
'
Dim fileBrowse As FileDialog
Dim UserSheetNumber As Long
Dim UserSheetConvertedName As String
'
Set fileBrowse = Application.FileDialog(msoFileDialogOpen)
'
If fileBrowse.Show = True Then wbPath = fileBrowse.SelectedItems(1)
'
With Workbooks.Open(wbPath)
UserSheetNumber = InputBox("Enter the number of the sheet you want to use.") ' Ask the user which sheet number to use
'
UserSheetConvertedName = Sheets(CLng(UserSheetNumber)).Name ' Convert sheet # to the actual sheet name ... TY @Fluff ;)
'
MsgBox "Sheet # Chosen by user = " & UserSheetNumber & vbCrLf & vbCrLf & "Sheet number selected by user converted to the corresponding sheet name = " & UserSheetConvertedName
Workbooks.Open(wbPath).Close ' Close the user chosen workbook
End With
End Sub