on open

izzyq

New Member
Joined
Mar 24, 2002
Messages
20
Is it possible for me to manipulate this code such that if the filename is OPEX Variance Analysis rev.2.xls it will run the macro, otherwise, nothing will happen.

Here is the code that I have so far.

Option Explicit



Private Sub Workbook_Open()
Dim filename As String
If filename = "Y:IQ38316DataExcelOPEX-CAPEX Input SheetsOPEX Variance Analysis rev.2.xls" Then

'set range you want to clear
Worksheets("Variance Analysis").Range("K30:T53").ClearContents

'returns OrgCode Values back to default "*" value
Worksheets("Variance Analysis").Range("C8:C10").Value = "*"

'returns month back to default of "01-January"
Worksheets("Variance Analysis").Range("B1").Value = "'01"

End If


End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hi. This is not good way.
Please try this, while you wait for other methods of other respondents.

'Please copy this into a standard module in PERSONAL.XLS
Sub BookNameCheck()
Dim filename As String, wb As Workbook
filename = "OPEX Variance Analysis rev.2.xls"
For Each wb In Workbooks
If wb.Name = filename Then
'set range you want to clear
Worksheets("Variance Analysis").Range("K30:T53").ClearContents
'returns OrgCode Values back to default "*" value
Worksheets("Variance Analysis").Range("C8:C10").Value = "*"
'returns month back to default of "01-January"
Worksheets("Variance Analysis").Range("B1").Value = "'01"
End If
Next
End Sub

'Copy this into ThisWorkbook module in Each Book
Private Sub Workbook_Open()
Application.Run "PERSONAL.XLS!BookNameCheck"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,168
Members
448,870
Latest member
max_pedreira

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
Back
Top