Wednesday, March 3, 2010

Master Page - Content Page Life Cycle

  1. Content page PreInit event.
  2. Master page controls Init event.
  3. Content controls Init event.
  4. Master page Init event.
  5. Content page Init event.
  6. Content page Load event.
  7. Master page Load event.
  8. Master page controls Load event.
  9. Content page controls Load event.
  10. Content page PreRender event.
  11. Master page PreRender event.
  12. Master page controls PreRender event.
  13. Content page controls PreRender event.
  14. Master page controls Unload event.
  15. Content page controls Unload event.
  16. Master page Unload event.
  17. Content page Unload event.
  18. The sequence of events in master

Friday, December 25, 2009

Programatically copy worksheet via VBA in Excel

Dim oBook As Workbook

Excel.Application.DisplayAlerts = False

Application.ScreenUpdating = False

Me.btnExportWorkSheet.TakeFocus<nClick = False

' Delete the Old File

Kill "c:\FileName.xls"

' Create a new blank workbook:

Set oBook = Application.Workbooks.Add

Application.SheetsInNewWorkbook = 1

' Add a defined name to the workbook

' that RefersTo a range:

oBook.Names.Add Name:="tempRange", RefersTo:="=Sheet1!$A$1"


' Save the workbook:

oBook.SaveAs "c:\FileName.xls"


' Select the Workbook where the Worksheet to be copied is located

Workbooks("Old File.xls").Activate

Workbooks("Old File.xls").Worksheets("Work Sheet A").Activate


' Copy the Worksheet to the Workbook

Worksheets("Work Sheet A").Copy Before:=Workbooks("New Work

Book.xls").Sheets(1)

Dim xRange As Range, adr As String

Workbooks("New Work Book.xls").Worksheets("Work Sheet A").Activate

Workbooks("New Work Book.xls").Worksheets("Work Sheet A").Range("a1:z100").Activate

' Remove Links and Replace with Cell Values

With Workbooks("New Work Book.xls").Worksheets("Work Sheet A")

Dim cCell As Range

Dim strValue As String

Set xRange = .Range("a1:z100")

For Each cCell In xRange

' Save the value to use as a means to identify what cells

to change

strValue = CStr(cCell.Value)

If InStr(strValue, "/") > 0 Then

cCell = CStr(cCell.Value)

End If

Next

End With

' Select the next Workbook where the Worksheet to be copied is located

Workbooks("Old File.xls").Activate

Workbooks("Old File.xls").Worksheets("Work Sheet B").Activate

' Copy the Worksheet to the Workbook

Worksheets("Work Sheet B").Copy Before:=Workbooks("CashFlowInput&DollarChart.xls").Sheets(1) ', UpdateLinks:=0

Workbooks("New Work Book.xls").Worksheets("Work Sheet B").Activate

Workbooks("New Work Book.xls").Worksheets("Work Sheet B").Range("a1:z100").Activate

' Remove Links and Replace with Cell Values

With Workbooks("New Work Book.xls").Worksheets("Dollars Chart")

Set xRange = .Range("a1:z100")

For Each cCell In xRange

' Save the value to use as a means to identify what cells to change

' cCell.Formula will show the link back to the Original

Workbook

strValue = CStr(cCell.Formula)

If InStr(strValue, "!") > 0 Then

cCell = CStr(cCell.Value)

' If cCell = .Range("b51") Or cCell = .Range("m4") Then

' Stop

' End If

End If

Next

End With

MsgBox ("Your Worksheets have been copied to C:\New Work Book.xls")

End Sub

Tuesday, September 29, 2009

Sort Excel workbook sheet alphabatically

Sub Sort_Active_Book()
Dim i As Integer
Dim j As Integer
Dim iAnswer As VbMsgBoxResult
'
' Prompt the user as which direction they wish to
' sort the worksheets.
'
iAnswer = MsgBox("Sort Sheets in Ascending Order?" & Chr(10) _
& "Clicking No will sort in Descending Order", _
vbYesNoCancel + vbQuestion + vbDefaultButton1, "Sort Worksheets")
For i = 1 To Sheets.Count
For j = 1 To Sheets.Count - 1
'
' If the answer is Yes, then sort in ascending order.
'
If iAnswer = vbYes Then
If UCase$(Sheets(j).Name) > UCase$(Sheets(j + 1).Name) Then
Sheets(j).Move After:=Sheets(j + 1)
End If
'
' If the answer is No, then sort in descending order.
'
ElseIf iAnswer = vbNo Then
If UCase$(Sheets(j).Name) < UCase$(Sheets(j + 1).Name) Then
Sheets(j).Move After:=Sheets(j + 1)
End If
End If
Next j
Next i
End Sub