Activate Next Sheet Shortcut and Activate Previous sheet Shortcut

Activate Next Sheet Shortcut and Activate Previous sheet Shortcut

k14348
Advocate Advocate
2,004 Views
2 Replies
Message 1 of 3

Activate Next Sheet Shortcut and Activate Previous sheet Shortcut

k14348
Advocate
Advocate

Hi,

  I'm planning to create a shortcut key for Previous Sheet Activate Shortcut and Next Sheet Activate Shortcut via Vba program. Can Anybody help?

 

-karthikeyan M

0 Likes
Accepted solutions (1)
2,005 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Accepted solution

Hi Karthi,

 

You can assign the key to the following macros using customize option available in the Tools Tab.

 

Snippet Code to activate next sheet of active sheet

 

Sub Forward()
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
Dim oSheetName As String
oSheetName = oDrawDoc.ActiveSheet.name
Dim oSheet As Sheet
Dim oSheetCount As Double
oSheetCount = oDrawDoc.Sheets.Count
i = 0
For Each oSheet In oDrawDoc.Sheets
    i = i + 1
    If oSheetName = oSheet.name Then
        If i < oSheetCount Then
            oDrawDoc.Sheets.Item(i + 1).Activate
        Else
            MsgBox "Reached Last Sheet"
        End If
    End If
Next
End Sub

Snippet Code to activate previous sheet

 

Sub Backward()
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
Dim oSheetName As String
oSheetName = oDrawDoc.ActiveSheet.name
Dim oSheet As Sheet
Dim oSheetCount As Double
oSheetCount = oDrawDoc.Sheets.Count
i = 0
For Each oSheet In oDrawDoc.Sheets
    i = i + 1
    If oSheetName = oSheet.name Then
        If i > 1 Then
            oDrawDoc.Sheets.Item(i - 1).Activate
        Else
            MsgBox "Reached First Sheet"
        End If
    End If
Next
End Sub
Message 3 of 3

nbonnett-murphy
Advocate
Advocate

If you come across this in 2023, you'll need to change a couple small things before you can paste these straight into an iLogic script.

 

Prev sheet:

Sub main()
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oSheetName As String
oSheetName = oDrawDoc.ActiveSheet.name
Dim oSheet As Sheet
Dim oSheetCount As Double
oSheetCount = oDrawDoc.Sheets.Count
i = 0
For Each oSheet In oDrawDoc.Sheets
    i = i + 1
    If oSheetName = oSheet.name Then
        If i > 1 Then
            oDrawDoc.Sheets.Item(i - 1).Activate
        Else
            MsgBox "Reached First Sheet"
        End If
    End If
Next
End Sub

 

Next sheet:

Sub main()
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oSheetName As String
oSheetName = oDrawDoc.ActiveSheet.Name
Dim oSheet As Sheet
Dim oSheetCount As Double
oSheetCount = oDrawDoc.Sheets.Count
i = 0
For Each oSheet In oDrawDoc.Sheets
    i = i + 1
    If oSheetName = oSheet.Name Then
        If i < oSheetCount Then
            oDrawDoc.Sheets.Item(i + 1).Activate
        Else
            MsgBox ("Reached Last Sheet")
        End If
    End If
Next
End Sub