Thread: help on a macro
View Single Post
  #2   Report Post  
Jim Rech
 
Posts: n/a
Default

Assuming you start the macro with the top, left cell selected that you want
to paste to, try this:

Sub LoadBOReport()
Dim PasteToCell As Range
Set PasteToCell = ActiveCell
Application.ScreenUpdating = False
Workbooks.OpenText Filename:="C:\DailyBackOrders\BackOrders.txt",
Origin:= _
437, StartRow:=1, DataType:=xlDelimited,
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False,
Comma:=False _
, Space:=False, Other:=True, OtherChar:="|",
FieldInfo:=Array(Array(1, 2 _
), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1),
Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13,
1), Array(14, 1), Array(15 _
, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1),
Array(20, 1)), _
TrailingMinusNumbers:=True
Rows("1:1").Insert
Range("A1").Value = "Item Nbr"
Range("B1").Value = "CO"
Range("C1").Value = "Desc"
Range("D1").Value = "Class"
Range("E1").Value = "Unit"
Range("F1").Value = "BO Qty"
Range("G1").Value = "S Qty"
Range("H1").Value = "OW"
Range("I1").Value = "Pick Nbr"
Range("J1").Value = "Cust Nbr"
Range("K1").Value = "Dept"
Range("L1").Value = "Dept Name"
Range("M1").Value = "Entered"
Range("N1").Value = "Due Date"
Range("O1").Value = "Cust PO"
Range("P1").Value = "WMP PO"
Range("Q1").Value = "Order Date"
Range("R1").Value = "Due Date"
Range("S1").Value = "Inv Date"
ActiveSheet.UsedRange.Copy PasteToCell
ActiveWorkbook.Close False
End Sub


--
Jim Rech
Excel MVP
"gls858" wrote in message
...
|I recorded macro that imports a text file and adds headers
| to the columns. When I run the macro it opens a new workbook
| and inserts the text file.
|
| Is is possible to add code that will copy the sheet from the
| new workbook into the original or just insert the imported
| file as a new sheet in the original workbook?
|
| Sub LoadBOReport()
| '
| ' Macro1 Macro
| ' Macro recorded 3/15/2005
| '
| ' Keyboard Shortcut: Ctrl+r
| '
| Workbooks.OpenText
| Filename:="C:\DailyBackOrders\BackOrders.txt", Origin:= _
| 437, StartRow:=1, DataType:=xlDelimited,
| TextQualifier:=xlDoubleQuote, _
| ConsecutiveDelimiter:=False, Tab:=False,
| Semicolon:=False, Comma:=False _
| , Space:=False, Other:=True, OtherChar:="|",
| FieldInfo:=Array(Array(1, 2 _
| ), Array(2, 1), Array(3, 1), Array(4, 1), Array(5,
| 1), Array(6, 1), Array(7, 1), Array(8, 1), _
| Array(9, 1), Array(10, 1), Array(11, 1), Array(12,
| 1), Array(13, 1), Array(14, 1), Array(15 _
| , 1), Array(16, 1), Array(17, 1), Array(18, 1),
| Array(19, 1), Array(20, 1)), _
| TrailingMinusNumbers:=True
| Rows("1:1").Select
| Selection.Insert Shift:=xlDown
| Range("A1").Select
| ActiveCell.FormulaR1C1 = "Item Nbr"
| Range("B1").Select
| ActiveCell.FormulaR1C1 = "CO"
| Range("C1").Select
| ActiveCell.FormulaR1C1 = "Desc"
| Range("D1").Select
| ActiveCell.FormulaR1C1 = "Class"
| Range("E1").Select
| ActiveCell.FormulaR1C1 = "Unit"
| Range("F1").Select
| ActiveCell.FormulaR1C1 = "BO Qty"
| Range("G1").Select
| ActiveCell.FormulaR1C1 = "S Qty"
| Range("H1").Select
| ActiveCell.FormulaR1C1 = "OW"
| Range("I1").Select
| ActiveCell.FormulaR1C1 = "Pick Nbr"
| Range("J1").Select
| ActiveCell.FormulaR1C1 = "Cust Nbr"
| Range("K1").Select
| ActiveCell.FormulaR1C1 = "Dept"
| Range("L1").Select
| ActiveCell.FormulaR1C1 = "Dept Nmae"
| Range("M1").Select
| ActiveCell.FormulaR1C1 = "Entered"
| Range("N1").Select
| ActiveCell.FormulaR1C1 = "Due Date"
| Range("O1").Select
| ActiveCell.FormulaR1C1 = "Cust PO"
| Range("P1").Select
| ActiveCell.FormulaR1C1 = "WMP PO"
| Range("Q1").Select
| ActiveCell.FormulaR1C1 = "Order Date"
| Range("R1").Select
| ActiveCell.FormulaR1C1 = "Due Date"
| Range("S1").Select
| ActiveCell.FormulaR1C1 = "Inv Date"
| End Sub
|
|