Reputation: 13
I am trying to get the name of a workbook and worksheet from the Application.InputBox
command in excel so that I can switch between the Active Workbook, and the workbook I have selected values from using the application.
I have code that works well selecting the values as a range, so I do not want to change that.
Here is what I have:
Sub test()
Dim rSelectDie As Range
Dim myWorkbook As String
Dim myWorksheet As String
Set rSelectDie = Application.InputBox(Prompt:="Please select the Die Values", Type:=8)
myWorkbook = ???
myWorksheet = rSelectDie.Worksheet.Name
MsgBox "Your Worksheet is: " & myWorksheet & vbNewLine & "Your WorkBook is" & myWorkbook
Windows(myWorkbook).Activate
Sheets(myWorksheet).Activate
End Sub
I am not sure what to put for the "???"
Upvotes: 1
Views: 3205
Reputation: 3410
perhaps
myWorkbook = rSelectDie.Worksheet.Parent.Name
or
myWorkbook = rSelectDie.Parent.Parent.Name
Upvotes: 2