-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserSelections.bas
More file actions
68 lines (46 loc) · 1.58 KB
/
Copy pathUserSelections.bas
File metadata and controls
68 lines (46 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Attribute VB_Name = "UserSelections"
Sub PickWorkbookAndSheet_OneClick()
Dim picked As Range
Dim wb As Workbook
Dim ws As Worksheet
MsgBox "Click any cell on the sheet you want to use.", vbInformation
On Error Resume Next
Set picked = Application.InputBox("Click a cell on the target sheet:", Type:=8)
On Error GoTo 0
If picked Is Nothing Then
MsgBox "No selection made."
Exit Sub
End If
Set ws = picked.Parent
Set wb = ws.Parent
MsgBox "You selected:" & vbCrLf & _
"Workbook: " & wb.Name & vbCrLf & _
"Sheet: " & ws.Name
' Continue your macro here
End Sub
Function PickSheetOneClick() As Worksheet
Dim picked As Range
MsgBox "Click any cell on the sheet you want to use.", vbInformation
' Allow clicking in other workbooks
Application.EnableEvents = False
Application.ScreenUpdating = False
On Error Resume Next
Set picked = Application.InputBox("Click a cell on the target sheet:", Type:=8)
On Error GoTo 0
Application.EnableEvents = True
Application.ScreenUpdating = True
If picked Is Nothing Then
MsgBox "No selection made."
Exit Function
End If
Set PickSheetOneClick = picked.Parent
End Function
Sub USELIKE_AskUserForWorkbookAndSheet()
Dim ws As Worksheet
Dim wb As Workbook
Set ws = PickSheetOneClick
If ws Is Nothing Then Exit Sub
Set wb = ws.Parent
MsgBox "Workbook: " & wb.Name & vbCrLf & "Sheet: " & ws.Name
Set TARGETWS = ws
End Sub