ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to run on openinng worksheet (https://www.excelbanter.com/excel-programming/308602-macro-run-openinng-worksheet.html)

Ian_Cee

Macro to run on openinng worksheet
 
Does anyone know how to make a macro run automatically
when you open a worksheet, and not have to rely on
hitting a button or a shortcut key?

I want the sheet to flash a couple of times, so this is
the code:

' Keyboard Shortcut: Ctrl+y
'
Cells.Select
With Selection.Interior
.ColorIndex = 1
.Pattern = xlSolid
End With
Cells.Select
Selection.Interior.ColorIndex = xlNone
Range("A1").Select
Cells.Select
With Selection.Interior
.ColorIndex = 1
.Pattern = xlSolid
End With
Cells.Select
Selection.Interior.ColorIndex = xlNone
Range("A1").Select

Cells.Select
With Selection.Interior
.ColorIndex = 1
.Pattern = xlSolid
End With
Cells.Select
Selection.Interior.ColorIndex = xlNone
Range("A1").Select

Cells.Select
With Selection.Interior
.ColorIndex = 1
.Pattern = xlSolid
End With
Cells.Select
Selection.Interior.ColorIndex = xlNone
Range("A1").Select

End Sub


Cheers

Arvi Laanemets

Macro to run on openinng worksheet
 
Hi

Do you want to flash the sheet, whenever you activate it, or when you open
the workbook.

When the 1st is the case, use worksheets Activate event (Alt+F11,
right-click on worksheet in VBA-Project window, select 'View code', in Code
window select Worksheet from dropdown list and Activate from another one).

When the 2nd is the case, use workbooks Open event (in VBA-Project window
right-click on ThisWorkbook, etc.)


--
Arvi Laanemets
(When sending e-mail, use address arvil<Attarkon.ee)


"Ian_Cee" wrote in message
...
Does anyone know how to make a macro run automatically
when you open a worksheet, and not have to rely on
hitting a button or a shortcut key?

I want the sheet to flash a couple of times, so this is
the code:

' Keyboard Shortcut: Ctrl+y
'
Cells.Select
With Selection.Interior
.ColorIndex = 1
.Pattern = xlSolid
End With
Cells.Select
Selection.Interior.ColorIndex = xlNone
Range("A1").Select
Cells.Select
With Selection.Interior
.ColorIndex = 1
.Pattern = xlSolid
End With
Cells.Select
Selection.Interior.ColorIndex = xlNone
Range("A1").Select

Cells.Select
With Selection.Interior
.ColorIndex = 1
.Pattern = xlSolid
End With
Cells.Select
Selection.Interior.ColorIndex = xlNone
Range("A1").Select

Cells.Select
With Selection.Interior
.ColorIndex = 1
.Pattern = xlSolid
End With
Cells.Select
Selection.Interior.ColorIndex = xlNone
Range("A1").Select

End Sub


Cheers




mangesh_yadav[_62_]

Macro to run on openinng worksheet
 
just put your code in a sub called Auto_open

for example

Sub Auto_Open()
' your code here
End Sub

- Manges

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 11:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com