Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro recorder help

Status
Not open for further replies.

scrappe7

Technical User
Jul 30, 2001
82
US
Hello, i am trying to fine tune a part of my database monster. I have an xls file that contains links to 6 other excel files and mixes and matches what i want from each into 1 nice spreadsheet. (Takes various data and moves to one file using links).

However, since i want to preserve this file and its links i have made a macro that would open up a new worksheet, copy all the data and paste special "as values". This makes a new sheet that the user could modify if they liked and the file with the links that grabs the data stays in tact. That works fine.

The problem is in copying charts/graphs that are located on a 2nd sheet in the links file. I can copy and paste them from the 'links' to the 'book1' manually and it will work. However, if i try to automate it using a macro i get "unable to get the ChartObjects property of the worlsheet class". Another problem is the macro records the creation of a new worksheet as either book1, book2, book3... etx. depending on how many books i have previously made before closing excel ( ie it continuously counts up). So if the macro is set and book1 was created if the next time i try run the macro and excel is passed book1 i get an error. i need to set the new workbook title to something stable, or let the user pick it before the macro is run?

Here is what the macro for copying the chart looks like.

Sub test2()
'
' test2 Macro
' Macro recorded 1/4/02 by Edward
'

'
ActiveWindow.Visible = False
Workbooks.Add
ActiveWindow.WindowState = xlMinimized
ActiveSheet.ChartObjects("Chart 1025").Activate
ActiveWindow.Visible = False
Windows("Quarterly Risk Summary.xls").Activate
Range("P3").Select
ActiveSheet.ChartObjects("Chart 1025").Activate
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy
ActiveWindow.Visible = False
Windows("Book3").Activate
ActiveWindow.WindowState = xlMaximized
ActiveSheet.Paste
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveWindow.Visible = False
Windows("Book3").Activate
Range("B32").Select
ActiveWindow.WindowState = xlMinimized
ActiveSheet.ChartObjects("Chart 1025").Activate
Windows("Quarterly Risk Summary.xls").SmallScroll Down:=18
ActiveWindow.Visible = False
Windows("Quarterly Risk Summary.xls").Activate
ActiveSheet.ChartObjects("Chart 1036").Activate
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy
ActiveWindow.Visible = False
Windows("Book1").Activate
ActiveWindow.WindowState = xlMaximized
ActiveWindow.SmallScroll Down:=6
Range("A34").Select
ActiveSheet.Paste
ActiveSheet.ChartObjects("Chart 2").Activate
Windows("Book3").SmallScroll Down:=21
ActiveWindow.Visible = False
ActiveWindow.WindowState = xlMinimized
ActiveSheet.ChartObjects("Chart 1036").Activate
End Sub


Again a stable file to paste the material, a way to paste the charts as well is needed, thanks.

Ed


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top