close workbook - dynamically

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,570
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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,897
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,114,337
Messages
5,547,357
Members
410,786
Latest member
dworkin
Top