Forum Discussion

GMSchaaf's avatar
GMSchaaf
Copper Contributor
Nov 11, 2019
Solved

can you 'set variable= workbook ' on click (from entry from an input box)?

I have this code where I get range data from a different workbook (than from where the code is run from) when prompted from an input box. I'd like to be able to capture this other workbook name as a ...
  • JKPieterse's avatar
    Nov 12, 2019

    GMSchaaf You need something along these lines:

    Sub GetWbFromRange()
        Dim Rng As Variant
        On Error Resume Next 'User might cancel, then the next line will fail
        Set Rng = Application.InputBox("Select the range please", , , , , , , 8)
        On Error GoTo 0
        If Not Rng Is Nothing Then
            MsgBox "Cell: " & Rng.Address & vbNewLine & "Worksheet: " & Rng.Parent.Name & vbNewLine & "Workbook: " & Rng.Parent.Parent.FullName
        End If
    End Sub

Resources