LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Replicating the Format Painter - to add to right-click menu

The control will remain on the Cell command bar until the Excel application
ends, even if you close the workbook that created it. If you want the
control to be accessible only when that one workbook is active, use code
like the following in the ThisWorkbook code module:


Private Const C_TAG = "MyFormatPainter"

Private Sub Workbook_Activate()

Dim Ctrl As Office.CommandBarControl
Set Ctrl = Application.CommandBars.FindControl(Tag:=C_TAG)
If Ctrl Is Nothing Then
Set Ctrl = CreateControl
End If
Ctrl.Visible = True
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.CommandBars.FindControl(Tag:=C_TAG).De lete
End Sub

Private Sub Workbook_Deactivate()
On Error Resume Next
Application.CommandBars.FindControl(Tag:=C_TAG).Vi sible = False
End Sub

Private Function CreateControl() As Office.CommandBarControl
Dim C As Office.CommandBarControl
Set C = Application.CommandBars("Cell").Controls.Add(ID:=1 08,
temporary:=True)
C.Tag = C_TAG
Set CreateControl = C
End Function



--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)




"Jim May" wrote in message
...
I only want this in a sample file - not all future or current workbooks.
Would I not add the code you provided to my Workbook.open
and then don't I need a On Workbook.Close
code to Remove it?

Thanks,

Jim May

"Chip Pearson" wrote:

Jim,

The following code will add the Format Painter to the right-click menu:

Application.CommandBars("Cell").Controls.Add ID:=108, temporary:=True


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Jim May" wrote in message
...
I was trying to replicate the format painter icon (on the toolbar) and
place
same
option on the short-cut menu. performed the below via a recorded
macro,
but
nee to be able the

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 10/13/2007 by Jim May

Selection.Copy
ActiveCell.Offset(4, 2).Range("A1").Select ' << Needs to be a
Clicked
cell in the spreadsheet - but how can I speak to that here???????
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
ActiveCell.Select
End Sub





 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Format Painter shortcut? LurfysMa New Users to Excel 6 August 25th 07 02:29 AM
how can I use the format painter?? hermosilla New Users to Excel 1 August 11th 06 11:56 PM
Can I use format painter (or F4) in a chart? Artemis Charts and Charting in Excel 1 June 20th 05 04:27 AM
how can i place the Format Painter icon on the Context menu? Saratusthra Excel Discussion (Misc queries) 2 June 8th 05 05:20 PM
Shortcut to format painter judith Excel Discussion (Misc queries) 2 January 17th 05 04:53 PM


All times are GMT +1. The time now is 03:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"