I have been working on this all day and I am thinking in circles - this would be a sweet Sub (Maybe a Func but how to exit on error?) current problem is
sWSName = sWBName.Parent.Name - error is: invalid qualifier
I am still in the middle of debugging this and am sure there are more errors that I haven't encountered - but like I said * BRAIN FOG *
Anyone want to give it a go?
sWSName = sWBName.Parent.Name - error is: invalid qualifier
I am still in the middle of debugging this and am sure there are more errors that I haven't encountered - but like I said * BRAIN FOG *
Anyone want to give it a go?
Code:
Sub OpenAndGetAll()
'
' Find and open a workbook, then choose a worksheet and cell
' Display the workbook name, the worksheet name, the column
' the Row and the chosen Cell (all as strings ).
'
Dim sWBName As String
Dim ws As Worksheet
Dim sWSName As String
Dim sCol As String
Dim sRow As String
Dim rRange As Range
Dim sCell As String
Dim sMSG As String
sWBName = Application.GetOpenFilename()
If (sWBName = "False") + (sWBName = "") Then Exit Sub
With Workbooks.Open(sWBName)
For Each ws In .Sheets
sMSG = sMSG & vbLf & ws.Name
Next
On Error Resume Next
Set rRange = Application.InputBox("Click on a cell on any sheet" & sMSG, Type:=8)
If rRange Is Nothing Then
MsgBox "You pressed cancel, macro terminating"
Exit Sub
Else
sCol = rRange.EntireColumn.Address(0, 0)
sCol = Left$(sCol, InStr(sCol, ":") - 1)
sRow = Right$(sCol, InStr(sCol, ":"))
sWSName = sWBName.Parent.Name
sCell = rRange
MsgBox "BookName = " & sWBName & vbLf & "Sheet Name = " & sWSName & vbLf & "Column = " & sCol & vbLf & "Row = " & sRow & vbLf & "Cell = " & sCell
End If
End With
End Sub