Friday

Learn Excel VBA By Index (D)



Delete


To delete a worksheet, use the following code..Worksheet(2) will be deleted

Sub DeleteSheetDemo1 ()

Worksheets(2).Delete

End Sub

When you delete a sheet, Excel will display a message to warn user whether they want to delete the sheet or not. To disable this message, use the code below

Sub DeleteSheetDemo2 ()

Application.DisplayAlerts = False

Worksheets(2).Delete

End Sub



Disable the Ctrl + Break and Esc key

In order for you to prevent user to stop a macro before it finish running by pressing the Ctrl + Break and Esc key, just insert the code below at the top of your procedure...

Application.EnableCancelKey = False



DisplayFullScreen

The macro below show you how to display fullscreen using Excel VBA

Application.DisplayFullScreen = True

To exit full screen using VBA then

Application.DisplayFullScreen = False



Do Until loop

When you use the Do Until loop, the code you enter between the Do and Loop will execute until the specified condition is met.

Sub DoDemo ( )

Dim x As Integer

x = 1

Do Until IsEmpty(Cells(x,1))

Cells(x,1).Font.Bold = True

x = x + 1

Loop

End Sub

The macro will execute until the cell in Column A is empty.

No comments: