ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Capture name of last worksheet opened (https://www.excelbanter.com/excel-programming/395184-capture-name-last-worksheet-opened.html)

Sliman

Capture name of last worksheet opened
 
I need to be able to run a macro when I open worksheet only if i
opened worksheet from a particual sheet.

if i open sheet 1 and was on sheet 2 i want macro in sheet 1 "on open"
to run
if i open sheet 1 and was on sheet 3 i want macrro in sheet 1 "on
open" no to run


Vergel Adriano

Capture name of last worksheet opened
 
something like this in the ThisWorkbook code module:


Dim strPreviousSheet As String
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Sh.Name = "Sheet1" And strPreviousSheet = "Sheet2" Then
'Call a sub defined in sheet1
Sheets(Sh.Name).test
End If
strPreviousSheet = Sh.Name
End Sub


--
Hope that helps.

Vergel Adriano


"Sliman" wrote:

I need to be able to run a macro when I open worksheet only if i
opened worksheet from a particual sheet.

if i open sheet 1 and was on sheet 2 i want macro in sheet 1 "on open"
to run
if i open sheet 1 and was on sheet 3 i want macrro in sheet 1 "on
open" no to run




All times are GMT +1. The time now is 03:33 AM.

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