0

IS there any way to check if an excel file is opened or not? If it is opened, then how can i close it?

thanks in advance

3
  • 3
    Why not start with a simple search? stackoverflow.com/a/9373914/2119523 Commented Mar 6, 2014 at 12:40
  • But there is no solution to close it Commented Mar 6, 2014 at 12:48
  • No, but you can tell by the votes which answer most people think is the best, and then try it. Commented Mar 6, 2014 at 13:16

1 Answer 1

1

If the workbook name does not include the period character, it can be as simple as:

Sub TestForOpen() Dim wb As Workbook, st As String st = "Phone" For Each wb In Workbooks stwb = Split(wb.Name, ".")(0) If st = stwb Then wb.Activate ActiveWorkbook.Close Exit Sub End If Next wb End Sub 

This one looks for an open workbook named Phone.xls or Phone.xlsx or ..................

If found the workbook is closed.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.