Sub AddSheet() Application.EnableEvents = False ThisWorkbook.Sheets.Add Application.EnableEvents = True End Sub
Tuesday, April 3, 2012
Disable Copy, Cut,Paste, Paste Special Menu in excel
Posted by AG at 10:55 PM 0 comments
Labels: Excel, Macro, paste value only, prevent right click
sample paste value only
http://www.jkp-ads.com/Download.asp#CatchPaste
Posted by AG at 10:53 PM 0 comments
Thursday, March 29, 2012
PAste value only for Ctrl -V
In this workboook:
Posted by AG at 1:56 AM 0 comments
Labels: Ctrl + V, Macro, paste value only
Tuesday, March 20, 2012
macro vba, remove all merge cell
Posted by AG at 12:51 AM 0 comments
Labels: Macro
Monday, March 19, 2012
merge cell vba macro
Posted by AG at 8:57 PM 0 comments
Labels: Macro, merge cell
Tuesday, March 13, 2012
Delete hidden rows
Sub DeleteHiddenRows_Workbook() 'This Microsoft Excel Macro will remove hidden rows from End Sub
'all worksheets in a workbook.
For i = 1 To Worksheets.Count
If Worksheets(i).Visible Then
Worksheets(i).Select
ActiveCell.SpecialCells(xlLastCell).Select
k = ActiveCell.Row
For j = 1 To k
If Rows(j).Hidden Then
Rows(j).Hidden = False
Rows(j).Delete
End If
Next j
End If
Next i
If Worksheets(1).Visible Then Worksheets(1).Select
Posted by AG at 1:49 AM 0 comments
Labels: delete hidden rows, Macro
Prevent user from delete worksheet
method 1:
Private Sub Worksheet_Activate()
Dim Ctrl As Office.CommandBarControl
For Each Ctrl In Application.CommandBars.FindControls(ID:=847)
Ctrl.Enabled = False
Next Ctrl
End Sub
Private Sub Worksheet_Deactivate()
Dim Ctrl As Office.CommandBarControl
For Each Ctrl In Application.CommandBars.FindControls(ID:=847)
Ctrl.Enabled = True
Next Ctrl
End Sub
----------------------------------------------------------------------------------------------------------------
Method 2:
Option Explicit
Private Sub Workbook_Activate()
Call Workbook_SheetActivate(ActiveSheet)
End Sub
Private Sub Workbook_Deactivate()
Call Indel
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ActiveSheet.Name = ("Data") _
Or ActiveSheet.Name = ("Query") _
Or ActiveSheet.Name = ("Sheet1") Then
Outdel
Else
Indel
End If
Next ws
End Sub
Private Sub Outdel()
Dim Ctrl As Office.CommandBarControl
For Each Ctrl In Application.CommandBars.FindControls(ID:=847)
Ctrl.Enabled = False
Next Ctrl
End Sub
Private Sub Indel()
Dim Ctrl As Office.CommandBarControl
For Each Ctrl In Application.CommandBars.FindControls(ID:=847)
Ctrl.Enabled = True
Next Ctrl
End Sub
----------------------------------------------------------------------------------------------------------------
Method 3:
Private Sub Worksheet_Activate()
Dim CB As CommandBar
Dim Ctrl As CommandBarControl
For Each CB In Application.CommandBars
Set Ctrl = CB.FindControl(ID:=847, recursive:=True)
If Not Ctrl Is Nothing Then
Ctrl.OnAction = "RefuseToDelete"
Ctrl.State = msoButtonUp
End If
Next
End Sub
Private Sub Worksheet_Deactivate()
Dim CB As CommandBar
Dim Ctrl As CommandBarControl
For Each CB In Application.CommandBars
Set Ctrl = CB.FindControl(ID:=847, recursive:=True)
If Not Ctrl Is Nothing Then Ctrl.OnAction = ""
Next
End Sub
Private Sub ResetDelete()
Dim CB As CommandBar
Dim Ctrl As CommandBarControl
For Each CB In Application.CommandBars
Set Ctrl = CB.FindControl(ID:=847, recursive:=True)
If Not Ctrl Is Nothing Then
Ctrl.Reset
Next CB
End Sub
'put in standard module
Public Sub RefuseToDelete()
MsgBox "This worksheet should not be deleted!", _
Buttons:=vbExclamation, _
Title:="Cannot Deleteworksheet!"
End Sub
Posted by AG at 12:36 AM 0 comments
Labels: Macro, Prevent user from delete worksheet, VBA
Sunday, March 11, 2012
Add-ins tab of the Ribbon
Posted by AG at 8:44 PM 0 comments
Labels: Add-in macros, Add-ins tab of the Ribbon, Macro
Tuesday, March 6, 2012
Excel Macro, VB
http://spreadsheetpage.com/index.php/file/C36/P20/
http://spreadsheetpage.com/index.php/files
- spreadsheet page with different macro and VB program, userform
http://spreadsheetpage.com/index.php/tip/C29
http://spreadsheetpage.com/index.php/tip/displaying_a_menu_of_worksheets_to_print/
tips
http://spreadsheetpage.com/index.php/tips
Posted by AG at 1:38 AM 0 comments
Labels: Excel, Macro, VBA UserForms and ActiveX Controls
Sunday, February 19, 2012
TOC
Sub CreateTableOfContents()
' Copyright 2002 MrExcel.com
' Determine if there is already a Table of Contents
' Assume it is there, and if it is not, it will raise an error
' if the Err system variable is > 0, you know the sheet is not there
Dim WST As Worksheet
On Error Resume Next
Set WST = Worksheets("Table of Contents")
If Not Err = 0 Then
' The Table of contents doesn't exist. Add it
Set WST = Worksheets.Add(Before:=Worksheets(1))
WST.Name = "TOC"
End If
On Error GoTo 0
' Set up the table of contents page
WST.[A2] = "Table of Contents"
With WST.[A6]
.CurrentRegion.Clear
.Value = "Subject"
End With
WST.[B6] = "Page(s)"
WST.Range("A1:B1").ColumnWidth = Array(36, 12)
TOCRow = 7
PageCount = 0
' Do a print preview on all sheets so Excel calcs page breaks
' The user must manually close the PrintPreview window
Msg = "Excel needs to do a print preview to calculate the number of pages. "
Msg = Msg & "Please dismiss the print preview by clicking close."
MsgBox Msg
ActiveWindow.SelectedSheets.PrintPreview
' Loop through each sheet, collecting TOC information
' Loop through each sheet, collecting TOC information
For Each S In Worksheets
If S.Visible = -1 Then
S.Select
' Use any one of the following 3 lines
ThisName = ActiveSheet.Name
'ThisName = Range("A1").Value
'ThisName = ActiveSheet.PageSetup.LeftHeader
HPages = ActiveSheet.HPageBreaks.Count + 1
VPages = ActiveSheet.VPageBreaks.Count + 1
ThisPages = HPages * VPages
' Enter info about this sheet on TOC
Sheets("TOC").Select
Range("A" & TOCRow).Value = ThisName
Range("B" & TOCRow).NumberFormat = "@"
If ThisPages = 1 Then
Range("B" & TOCRow).Value = PageCount + 1 & " "
Else
Range("B" & TOCRow).Value = PageCount + 1 & " - " & PageCount + ThisPages
End If
PageCount = PageCount + ThisPages
TOCRow = TOCRow + 1
End If
Next S
End Sub
Posted by AG at 11:51 PM 0 comments
Labels: Macro, Microsoft Visual Basic, table of content
Friday, February 17, 2012
The Method to manage too many excel sheet in workbook
Add-in to hide and show the worksheets in excel file. It helps alot when there's many worksheets in a single workbook
http://www.grbps.com/addhid.htm
description of add-in macro code
http://www.grbps.com/ExcelB.pdf
Posted by AG at 12:42 AM 0 comments
Labels: Excel, hide worksheet, Macro, Microsoft Visual Basic
Thursday, February 16, 2012
Excel
'Add a Sheet After Last Sheet in a Single Action [1]
Sub AddNewSheet()
Application.ScreenUpdating = False ' Prevents screen refreshing.
' This line adds a new worksheet to the workbook. Alternatively, use:
'
' DialogSheets.Add Adds a dialog sheet.
' Charts.Add Adds a chart sheet.
' Modules.Add Adds a Visual Basic module.
' Sheets.Add Type:=xlExcel4MacroSheet Adds an MS Excel 4.0 macro
' sheet.
Worksheets.Add
' This line makes the new sheet (which is also the active sheet) the
' last sheet in the workbook.
ActiveSheet.Move After:=Sheets(ActiveWorkbook.Sheets.Count)
Application.ScreenUpdating = True ' Enables screen refreshing.
End Sub
Posted by AG at 6:54 AM 0 comments
Labels: Excel, Macro, Microsoft Visual Basic
Thursday, February 9, 2012
Force user to enable macro in Excel
http://www.excelguru.ca/content.php?162
Posted by AG at 1:30 AM 0 comments
Labels: Excel, Force user to enable macro in Excel, Macro, Microsoft Visual Basic