Changing the Recorded Code

Using the five tips given in this chapter,you can convert the recorded code into efficient, professional-looking code. Here is the code as recorded by the macro recorder:

Importlnvoice Macro

Recorded 10/23/2003 by Bill Jelen This macro will import invoice.txt and add totals.

Keyboard Shortcut: Ctrl+i

Workbooks.OpenText Filename:= _

:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote , ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=True , Space:=False, Other:=False, FieldInfo:=Array(Array(1, 3), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1)), _ TrailingMinusNumbers:=True Selection.End(xlDown).Select Range("A14").Select ActiveCell.FormulaR1C1 = "'Total" Range("E14").Select

Selection.FormulaR1C1 = "=SUM(R[-12]C:R[-1]C)"

Selection.AutoFill Destination:=Range("E14:G14"), Type:=xlFillDefault



Selection.Font.Bold = True


Selection.Font.Bold = True


Selection.Columns.AutoFit End Sub

0 0

Post a comment