VBA to check file name of active workbook

Kayslover

Board Regular
Joined
Sep 22, 2020
Messages
153
Office Version
  1. 2013
Platform
  1. Windows
Hi all,

I have a macro that opens a file, calls another macro using the Call statement (Call E_DoRepeatWork_AllWorkbooks).

The called macro does processing and one of the last statements in this macro is to close the active workbook, and then return from where it come from.

What I need to achieve in E_DoRepeatWork_AllWorkbooks is, if the current file name is "12 December" (or even check the first 6 characters, if its faster) then NOT to close the active workbook.

Is what I am asking for possible?

Any assistance offered will be appreciated.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

offthelip

Well-known Member
Joined
Dec 23, 2017
Messages
1,818
Office Version
  1. 2010
Platform
  1. Windows
It is very easy to check the actrive workbook name : like this:
VBA Code:
Dim sts As String
sts = ActiveWorkbook.Name
If Left(sts, 6) = "12 Dec" Then
 MsgBox (sts)
Else
 ActiveWorkbook.Close
End If
 
Solution

Kayslover

Board Regular
Joined
Sep 22, 2020
Messages
153
Office Version
  1. 2013
Platform
  1. Windows
Offthelip,

Many thanks, worked a treat as expected. 👍 👍
 

Watch MrExcel Video

Forum statistics

Threads
1,130,029
Messages
5,639,624
Members
417,101
Latest member
amoverton2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top