Thread: Macro Help
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Macro Help

Try these changges

Sub test()
'
' test Macro
'

'
Set NewSht = ThisWorkbook.ActiveSheet
ChDir "C:\Users\j.dibble.CTS\Desktop"
Set CSVFvile =
Workbooks.Open(FileName:="C:\Users\j.dibble.CTS\De sktop\test.csv")
CSVFile.ActiveSheet.Range("A1:B5").Copy _
Destination:=NewSht.Range("A1")
Application.CutCopyMode = False

With NewSht.Columns("A:B")
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Application.DisplayAlerts = False
ThisWorkbook.SaveAs FileName:= _
"C:\Users\j.dibble.CTS\Desktop\testenabled.xls m", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled
Application.DisplayAlerts = True
End Sub



"Jon Dibble" wrote:

Hi I am trying to write a Macro that opens another workbook (test.csv) and
copies the data from and places into the workbook with the macro
(testenabled.xmls) which will run on a scheduled task.

I keep running into this error

run time error '9'
subscript out of range

Here is the code - I would really appreciate some help.

Sub test()
'
' test Macro
'

'
ChDir "C:\Users\j.dibble.CTS\Desktop"
Workbooks.Open Filename:="C:\Users\j.dibble.CTS\Desktop\test.csv"
Range("A1:B5").Select
Selection.Copy
Windows("Book1").Activate
ActiveSheet.Paste
Columns("A:B").Select
Range("B1").Activate
Application.CutCopyMode = False
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("A2").Select
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
"C:\Users\j.dibble.CTS\Desktop\testenabled.xls m", FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Application.DisplayAlerts = True

End Sub