close workbook - dynamically

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,565
Hi
I want to ask user to enter workbook number to close and then close that workbook accordingly. So I wrote the code below, but did not run. Any help would be appreciated. Thank you.

Code:
Sub mywb2()
    Dim x As Integer
    x = InputBox("which workbook")
    "workbooks" &x.close
End Sub
 

Some videos you may like

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,508
Office Version
  1. 365
Platform
  1. Windows
What do you mean by "workbook number"?
What exactly would they be entering?
Do you mean the name of the workbook?
 

Watch MrExcel Video

Forum statistics

Threads
1,109,455
Messages
5,528,879
Members
409,844
Latest member
ardask
Top