View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
tskogstrom tskogstrom is offline
external usenet poster
 
Posts: 92
Default How unselect? Want to run ActiveWindow.VisibleRange but have Chartobject selected

I move charts from sheet2 to sheet1 and back again with these two
procedures. With a chartobject named "CHT5" in sheet2 you should be
able to test the code. Error come on line "Set rng =
ActiveWindow.VisibleRange" and I guess it is because activewindow is
the window the chartobject is within and it doesn't have ".
VisibleRange".

The row "Sheet2.ChartObjects("CHT5").Chart.Location
Whe=xlLocationAsObject, _ Name:=ActiveSheet.Name" seem to always
select the chartobject of some reason ...

Therefo How can I unselect the chartobject window to the ordinary
range selection on the worksheet and be able to run the code? Excel
seems to need something always selected.

I don't want to select A1 or something but want to have the last range
selection still intact after "MoveBackChart" is used!


Sub InsertChartMiddle()
Dim picWd As Integer
Dim picHt As Integer
Dim rng As Range
If Sheet3.Range("A1").Value = 0 Then
Sheet2.ChartObjects("CHT5").Chart.Location
Whe=xlLocationAsObject, _ Name:=ActiveSheet.Name

'Find middle of window
ActiveSheet.Select
Set rng = ActiveWindow.VisibleRange ' ERROR
cTop = rng.Top + 0.5 * rng.Height
cWidth = rng.Left + 0.5 * rng.Width

'Notify the Chartobject shows
Sheet3.Range("A1").Value= 1
End If
End Sub

Sub MoveBackChart()
On Error Resume Next
ActiveSheet.ChartObjects("CHT5").Chart.Location
Whe=xlLocationAsObject, Name:="Sheet2"
Sheet3.Range("A1").Value = 0
End Sub

Grateful to all help

Regards,
tskogstrom