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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,929
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,528
Messages
5,548,576
Members
410,852
Latest member
WernerS
Top