How to Create a Template Header in Excel Using VB6
One of the benefits of creating Microsoft Excel files using Visual Basic 6 is the ability to export the created files via email. The size is smaller, since the code can be sent as a text file, and the time for uploading files is significantly diminished. Creating Excel spreadsheets in this way is a straightforward process, since Microsoft provides pre-written classes containing properties and methods that are customizable.
Instructions
-
-
1
Open Microsoft Excel. Open the Visual Basic Editor by pressing "Alt" and "F11" at the same time.
-
2
Access the Worksheet class by using the "Dim" command. This class contains the predefined methods to add a header to Microsoft Excel files. A sample line of code is "Dim ws as Excel.Worksheet."
-
-
3
Decide on the type of header to be used. The most common ones are left, center and right header.
-
4
Set the header of the Microsoft Excel file using the Header property that is already defined in the Worksheet class. For instance, if using the variable defined in Step 1, the command ws.LeftHeader = "string" should be used for defining a left-aligned center. Replace "string" with any text.
-
5
Use the "&" character for variables. For example, "&P" will display the current page and "&N" will display the total number of pages of the document.
-
6
Press "Ctrl" and "S" at the same time to save the Visual Basic 6 code.
-
7
Press "F5" if running the Visual Studio IDE in order to compile and run the code. If using a different IDE, locate the "compile" and "run" options.
-
1
References
- Photo Credit Duncan Smith/Photodisc/Getty Images