#1   Report Post  
Posted to microsoft.public.excel.programming
TOM TOM is offline
external usenet poster
 
Posts: 47
Default Excel Macro

I created a macro (using recorder) in Excel 2000 that
toggles between two workbooks (histdata.xls and test.xls)
among other things. The macro works fine when I run it
manually but bombs and gives me an error 9 "subscript out
of range" when it reaches the line "Windows
("HISTDATA.xls").Activate" when it runs automatically. I
want the macro to run automatically every time I open the
workbook so I copied the macro to the VB editor in VBA
Projects under "This Workbook" and added Workbook_open()
to run it automatically. Here is the macro:

Private Sub Workbook_Open()

Range("B5:J5").Select
Workbooks.Open Filename:="C:\HISTDATA.CSV"
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Selection.CurrentRegion.Select
ChDir "C:\"
ActiveWorkbook.SaveAs Filename:="C:\HISTDATA.xls",
FileFormat:=xlNormal, _
Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False, _
CreateBackup:=False
Selection.Cut
Windows("test.xls").Activate
Range("B10").Select
ActiveSheet.Paste
Windows("HISTDATA.xls").Activate
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub

Please help!!

Thanks

Tom
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Excel Macro

To

Change the line to
Workbooks("HISTDATA.xls").Activat

Ton
----- Tom wrote: ----

I created a macro (using recorder) in Excel 2000 that
toggles between two workbooks (histdata.xls and test.xls)
among other things. The macro works fine when I run it
manually but bombs and gives me an error 9 "subscript out
of range" when it reaches the line "Window
("HISTDATA.xls").Activate" when it runs automatically. I
want the macro to run automatically every time I open the
workbook so I copied the macro to the VB editor in VBA
Projects under "This Workbook" and added Workbook_open()
to run it automatically. Here is the macro

Private Sub Workbook_Open(

Range("B5:J5").Selec
Workbooks.Open Filename:="C:\HISTDATA.CSV
Rows("1:1").Selec
Selection.Delete Shift:=xlU
Range("A1").Selec
Selection.CurrentRegion.Selec
ChDir "C:\
ActiveWorkbook.SaveAs Filename:="C:\HISTDATA.xls",
FileFormat:=xlNormal,
Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False,
CreateBackup:=Fals
Selection.Cu
Windows("test.xls").Activat
Range("B10").Selec
ActiveSheet.Past
Windows("HISTDATA.xls").Activat
ActiveWorkbook.Sav
ActiveWorkbook.Clos
End Su

Please help!

Thank

To

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 1 February 5th 07 09:31 PM
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 3 February 5th 07 08:22 PM
passing variables from an excel macro to a powerpoint macro jake Excel Programming 1 December 11th 03 02:36 AM


All times are GMT +1. The time now is 05:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"