Roman Ivanov
Roman Ivanov

Reputation: 59

closing an active excel file knowing fraction of the name

I have opened a file given the fraction of the name, where i equals to 142 as per below code. Workbooks.Open Filename:=FilePath3 & "" & i & "."

After switching back and forth between other files is it possible to return back to this file and close it? I cant figure out how to Reference/Activate it, given I only have fraction of the name.

Thanks

Upvotes: 0

Views: 366

Answers (1)

tretom
tretom

Reputation: 625

I guess, after you open this file it's automatically activated, so I'd make it like:

Dim fileName as String
Workbooks.Open Filename:=FilePath3 & "" & i & "."
fileName = ActiveWorkbook.Name

and from this moment you can close your file at any time with something like:

Workbooks(fileName ).Close (False)

use (False) only if you don't want to save it

Upvotes: 2

Related Questions