Choosing a WBName and WSName Debug help please

DChambers

Active Member
Joined
May 19, 2006
Messages
257
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?

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
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Code:
Dim sWBName As String

Strings don't have .Parents.

Try
Code:
sWSName = ActiveWorkbook.Name
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top