Info

The help file confirms that OpenText is a method or an action word. In the grey box is the default order for all the arguments that can be used with OpenText. Notice that only one argument is required—FileName. All the other arguments are listed as optional.

Optional Parameters

What happens if you skip an optional parameter? The help file can tell you. For StartRow, the help file indicates that the default value is 1. If you leave out the StartRow parameter, Excel starts importing at Row 1. This is fairly safe. Look at the help file note about Origin. If this argument is omitted, then you inherit whatever value was used for Origin the last time someone used this feature in Excel on this computer. That is certainly a recipe for disaster—your code may work 98% of the time, but immediately after someone imports an Arabic file, Excel will remember the setting for Arabic and assume this is what your macro wants if you don't explicitly code this parameter.

Defined Constants

Look at the help file entry for DataType in Figure 2.8. The help file says that it can be one of these constants: xlDelimited or xlFixedWidth. The help file says that these are the valid xlTextParsingType constants. These constants are pre-defined in Excel VBA. In the VB Editor, hit Ctrl+G to bring up the Immediate pane. In the Immediate pane, type this line and press Enter:

Print xlFixedWidth

The answer appears in the Immediate pane. xlFixedWidth is the equivalent of saying "2" (see Figure 2.8). Ask the Immediate pane to Print xlDelimited. This is really the same as typing 1. Microsoft correctly assumes that it is easier for someone to read code that uses the somewhat English-like term xlDelimited instead of 1.

0 0

Post a comment