How unselect? Want to run ActiveWindow.VisibleRange but have Chartobject selected

T

tskogstrom

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
Where:=xlLocationAsObject, _ Name:=ActiveSheet.Name" seem to always
select the chartobject of some reason ...

Therefore: 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
Where:=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
Where:=xlLocationAsObject, Name:="Sheet2"
Sheet3.Range("A1").Value = 0
End Sub

Grateful to all help

Regards,
tskogstrom
 
T

Tom Ogilvy

Sheet2.ChartObjects("CHT5").Chart.Location
Where:=xlLocationAsObject, _
Name:=ActiveSheet.Name"
ActiveCell.Select
 
T

tskogstrom

Hi Tom,
Thank you for your help.

On line Activecell.select, I get Error "Object variable och With block
not set" or something like that.

Ideas?

regards
tskogstrom

Tom Ogilvy skrev:
 
T

Tom Ogilvy

sound like an implementation problem on your part. Activecell is defined
and set by Excel/VBA.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top