Page 234 - CITS - Computer Software Application -TT
P. 234

COMPUTER SOFTWARE APPLICATION - CITS




           Importing macros
           To import a bas file with VBA codes into your Excel, please follow these steps:
           1  Open the workbook into which you want to import macros.
           2  Open the Visual Basic Editor.

           3  In the Project Explorer, right-click the project name and select Import File.
           4  Navigate to the bas file and click Open.


































           Excel macro examples

           One of the best ways to learn Excel VBA is by exploring code samples. Below you will find examples of very
           simple VBA codes that automate some basic operations. Of course, these examples won't teach you coding, for
           this there exist hundreds of professional-grade VBA tutorials. We just aim to illustrate a few common features of
           VBA that will hopefully make its philosophy a little more familiar to you.
           Unhide all sheets in a workbook
           In this example, we use the Active Workbook object to return the currently active workbook and the For Each
           loop to go through all the sheets in the workbook one-by-one. For each found sheet, we set the Visible property
           to xlSheetVisible.
           Sub Unhide_All_Sheets () Dim wks. As Worksheet For Each wks. In ActiveWorkbook.Worksheets wks. Visible =
           xlSheetVisible Next wks. End Sub
           Hide active worksheet or make it very hidden

           To manipulate the currently active sheet, use the Active Sheet object. This sample macro changes the visible
           property of the active sheet to xlSheetHidden to hide it. To make the sheet very hidden, set the visible property
           to xlSheetVeryHidden.
           Sub Hide_Active_Sheet () ActiveSheet.Visible = xlSheetHidden End Sub
           Unmerge all merged cells in selected range
           If you want to perform certain operations on a range rather than the entire worksheet, use the Selection object.
           For example, the below code will unmerge all the merged cells in a selected range at one fell swoop.
           Sub Unmerge Cells () Selection.Cells.UnMerge End Sub




                                                           221

                             CITS : IT&ITES - Computer  Software Application - Lesson 63 - 77
   229   230   231   232   233   234   235   236   237   238   239