Macro for key combinations

peperosso

New Member
Joined
Oct 13, 2015
Messages
8
Hi everyone,
I am trying to write a macro to rename my sheets in excel. My idea is that of using a key combination to open the propriety window of the development tab. The sequence of keys that allows to open the window is ALT,Q,P. Therefore my macro would sound like the following:

Sub rename_sheet()
SendKeys ("{%}")
SendKeys ("{Q}")
SendKeys ("{P}")
End Sub

However the macro is not working properly. Do you have any idea of why?
Thank you in advance for your help!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
SendKeys is incredibly unreliable. Since you're already using code, why not let the code change the sheet name? Definitely less messy.

Code:
Sub Rename_Sheet()
ActiveSheet.Name = "New Sheet 1"
End Sub
 
Upvote 0
If you have a large number of sheets and want to rename them do this.
On your first sheet in column "A" List all the names you want to name your sheets.

For example in Sheet(1) which is the sheet in the far left position on your tab bar.
In Range("A1") enter the name you want sheet(1) named
In Range("A2") enter the name you want sheet(2) named

And continue doing this for as many sheets as you have.
Now run this script:

Code:
Sub Rename_Sheets()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Sheets(1).Activate
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To Sheets.Count
        Sheets(i).Name = Cells(i, 1).Value
    Next
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,022
Messages
6,128,325
Members
449,440
Latest member
Gillian McGovern

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