Info

It is possible to select the code, copy it to the clipboard with Ctrl+C (see Figure 2.5), then paste it into your module using Ctrl+V.

Figure 2.5

Highlight code in the help file and copy with Ctrl+C.

NKgllox l nnrtinn Example

This example use; the Mvgllax Function to display a critical-error message in a dialog hoy. with Yes and No buttons. The No button is specified as the default response. The value returned by the iMsgBox function depends on the button chosen by the user. This example assumes that DEMO. HLP is a Help file that contains a topic with a Help context number equal to 1000.

This example use; the Mvgllax Function to display a critical-error message in a dialog hoy. with Yes and No buttons. The No button is specified as the default response. The value returned by the iMsgBox function depends on the button chosen by the user. This example assumes that DEMO. HLP is a Help file that contains a topic with a Help context number equal to 1000.

Example Scripts For Excel

After you record a macro, undoubtedly there will be objects or methods that you are not sure of. Insert the cursor in any keyword and press F1 to get help on that topic.

Examining Recorded Macro Code—Using the VB Editor and Help

Let's take a look at the code that was recorded in Chapter 1, "Unleash the Power of Excel with VBA!" to see whether it makes more sense now in the context of objects, properties, and methods. You can also see whether it's possible to correct the errors brought about by the macro recorder.

Here is the first code that Excel recorded in Chapter 1 (see Figure 2.6).

Figure 2.6

Recorded code.

Sub IttipDct 2r«voice([

Hacro recorded 10/23/2003 by Bill Jelea This nacco will lapoci invoiceitxt and add t ' Keyboard iiJioCtcut: Ctrl+1

"C:^ invoice.cxt", Origin

Sianlwí'li íac*Trpí!«*lB*lüúlMdí TextQvau itiet = »«u<XMi»leOi*ote _ , CoHEecuciveDeilnilcer ¡-False, Tab;-True, 2eniCDlan¡-False, Caima!-True _

ir my 13 r iif»v|1, 1), ¡k«*y(ír It, *»t*y(fir If, tl(«f|?, If}* Tt* J £ LxiQItl Kit

Sei«tí<ni-Cras{*jeíiiisi -Select F:an5B .Select

AeiivsCíU.reíBmiéJUCJi • ""T«*!"

3election.roraulaRlCl - ""50B(R(-12JC:R[-1JC] "

felKlKn.iuioriti (*Cl4í414H) , Tvp-i-Kjri J mrf«uit

Bona("lil-J.Select iei«ti«t.ri»t.Oi>ia - Teve

Selection-font. Sold - Teve fella. Select

Now that you understand the concept of Noun.Verb or Object.Method, look at the first line of code. It says Workbooks.OpenText. In this case, Workbooks is an object. OpenText is a method. Click your cursor inside the word OpenText and press F1 for an explanation of the OpenText method (see Figure 2.7).

Figure 2.7

Help topic for the OpenText Method. Methods usually have an Applies To link on the second line,which helps to identify when you can use a particular method.

Figure 2.7

Help topic for the OpenText Method. Methods usually have an Applies To link on the second line,which helps to identify when you can use a particular method.

Example Dynamic Userforms
0 0

Post a comment