Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default getting the active chart/chartobject's name

Given the code below, does anyone have any suggestions on how to
obtain the active chart/chartobject's name so that I can address
Shape(name) properly when I try ot move the shape?

Code:
Sub LT(wbname As String, wsname As String)   ' Graphing Lifetime
Results
    Dim normalgraph As Chart                ' normal graph variable
    Dim regressgraph As Chart               ' regression graph
variable
    Dim twoGraphs As ChartObjects              'Chartobjects for
embedded charts

    Dim ngName As String                'normal graph name for moving
the chart
    Dim rgName As String                'regression graph name for
moving the chart

    Dim i As Long                           ' loop counter
    Dim colEnd As Long                         ' end of a column

    Workbooks(wbname).Sheets(wsname).Activate       'activate
worksheet of interest

    Let colEnd = Range("c2").End(xlDown).Row

    ' Select data range
    Range(Cells(2, 2), Cells(colEnd, 6)).Select

    ' insert new graph for showing Fuel cell voltage, flow,
temperature,
    ' and fuel cell current
    Set normalgraph = Charts.Add
    Set normalgraph = normalgraph.Location(whe=xlLocationAsObject,
Name:=wsname)
    ngName = normalgraph.Name

    'more code
Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default getting the active chart/chartobject's name

How about this?


With .ActiveWorkbook
.Sheets("Sheet1").Select
.ActiveSheet.ChartObjects("Chart 1").Activate
.ActiveChart.ChartArea.Copy
End With


On Dec 21, 11:26*am, Stanley wrote:
Given the code below, does anyone have any suggestions on how to
obtain the active chart/chartobject's name so that I can address
Shape(name) properly when I try ot move the shape?

Code:
 Sub LT(wbname As String, wsname As String) * ' Graphing Lifetime
 Results
 * * Dim normalgraph As Chart * * * * * * * *' normal graph variable
 * * Dim regressgraph As Chart * * * * * * * ' regression graph
 variable
 * * Dim twoGraphs As ChartObjects * * * * * * *'Chartobjects for
 embedded charts

 * * Dim ngName As String * * * * * * * *'normal graph name for moving
 the chart
 * * Dim rgName As String * * * * * * * *'regression graph name for
 moving the chart

 * * Dim i As Long * * * * * * * * * * * * * ' loop counter
 * * Dim colEnd As Long * * * * * * * * * * * * ' end of a column

 * * Workbooks(wbname).Sheets(wsname).Activate * * * 'activate
 worksheet of interest

 * * Let colEnd = Range("c2").End(xlDown).Row

 * * ' Select data range
 * * Range(Cells(2, 2), Cells(colEnd, 6)).Select

 * * ' insert new graph for showing Fuel cell voltage, flow,
 temperature,
 * * ' and fuel cell current
 * * Set normalgraph = Charts.Add
 * * Set normalgraph = normalgraph.Location(whe=xlLocationAsObject,
 Name:=wsname)
 * * ngName = normalgraph.Name

 * * 'more code

Thanks!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default getting the active chart/chartobject's name

On Dec 21, 11:36 am, brittonsm wrote:
How about this?

With .ActiveWorkbook
.Sheets("Sheet1").Select
.ActiveSheet.ChartObjects("Chart 1").Activate
.ActiveChart.ChartArea.Copy
End With

On Dec 21, 11:26 am, Stanley wrote:

Given the code below, does anyone have any suggestions on how to
obtain the active chart/chartobject's name so that I can address
Shape(name) properly when I try ot move the shape?


Code:
  Sub LT(wbname As String, wsname As String)   ' Graphing Lifetime
  Results
      Dim normalgraph As Chart                ' normal graph variable
      Dim regressgraph As Chart               ' regression graph
  variable
      Dim twoGraphs As ChartObjects              'Chartobjects for
  embedded charts
Code:

      Dim ngName As String                'normal graph name for moving
  the chart
      Dim rgName As String                'regression graph name for
  moving the chart

      Dim i As Long                           ' loop counter
      Dim colEnd As Long                         ' end of a column

      Workbooks(wbname).Sheets(wsname).Activate       'activate
  worksheet of interest

      Let colEnd = Range("c2").End(xlDown).Row

      ' Select data range
      Range(Cells(2, 2), Cells(colEnd, 6)).Select

      ' insert new graph for showing Fuel cell voltage, flow,
  temperature,
      ' and fuel cell current
      Set normalgraph = Charts.Add
      Set normalgraph = normalgraph.Location(whe=xlLocationAsObject,
  Name:=wsname)
      ngName = normalgraph.Name

      'more code
  


Thanks!


The problem is that I don't know for certain the name inside the
chartobjects() identifier or shapes() identifier.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default getting the active chart/chartobject's name

after this line
ngName = normalgraph.Name

add
sChtObjName = normalgraph.Parent.Name

If all you want to do is move it with in the same routine as you created it,
simply

With normalgraph.Parent
..Left = 10
..Top = 20
' .width & .height if necessary
End With

However, no need to first add a chart sheet, add the chartobject to the
requisite sheet, sized to suit, eg

Sub test2()
Dim chtObj As ChartObject
Dim cht As Chart
Dim cell As Range

Set cell = ActiveSheet.Range("B3")

With cell
Set chtObj = ActiveSheet.ChartObjects.Add(.Left, .Top, 300, 200)
End With

Set cht = chtObj.Chart

With cht
' build the chart

End With

End Sub

Regards,
Peter T

"Stanley" wrote in message
...
Given the code below, does anyone have any suggestions on how to
obtain the active chart/chartobject's name so that I can address
Shape(name) properly when I try ot move the shape?

Code:
 Sub LT(wbname As String, wsname As String)   ' Graphing Lifetime
 Results
     Dim normalgraph As Chart                ' normal graph variable
     Dim regressgraph As Chart               ' regression graph
 variable
     Dim twoGraphs As ChartObjects              'Chartobjects for
 embedded charts

     Dim ngName As String                'normal graph name for moving
 the chart
     Dim rgName As String                'regression graph name for
 moving the chart

     Dim i As Long                           ' loop counter
     Dim colEnd As Long                         ' end of a column

     Workbooks(wbname).Sheets(wsname).Activate       'activate
 worksheet of interest

     Let colEnd = Range("c2").End(xlDown).Row

     ' Select data range
     Range(Cells(2, 2), Cells(colEnd, 6)).Select

     ' insert new graph for showing Fuel cell voltage, flow,
 temperature,
     ' and fuel cell current
     Set normalgraph = Charts.Add
     Set normalgraph = normalgraph.Location(whe=xlLocationAsObject,
 Name:=wsname)
     ngName = normalgraph.Name

     'more code

Thanks!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default getting the active chart/chartobject's name

Hi,

Try this code,

'----------
Set normalgraph = Charts.Add
Set normalgraph = _
normalgraph.Location(whe=xlLocationAsObject, Name:=wsname)

With Worksheets(wsname)
Set normalgraph = .ChartObjects(.ChartObjects.Count).Chart
End With
ngName = normalgraph.Parent.Name
'----------

Cheers
Andy

Stanley wrote:
Given the code below, does anyone have any suggestions on how to
obtain the active chart/chartobject's name so that I can address
Shape(name) properly when I try ot move the shape?

Code:
 Sub LT(wbname As String, wsname As String)   ' Graphing Lifetime
 Results
     Dim normalgraph As Chart                ' normal graph variable
     Dim regressgraph As Chart               ' regression graph
 variable
     Dim twoGraphs As ChartObjects              'Chartobjects for
 embedded charts
 
     Dim ngName As String                'normal graph name for moving
 the chart
     Dim rgName As String                'regression graph name for
 moving the chart
 
     Dim i As Long                           ' loop counter
     Dim colEnd As Long                         ' end of a column
 
     Workbooks(wbname).Sheets(wsname).Activate       'activate
 worksheet of interest
 
     Let colEnd = Range("c2").End(xlDown).Row
 
     ' Select data range
     Range(Cells(2, 2), Cells(colEnd, 6)).Select
 
     ' insert new graph for showing Fuel cell voltage, flow,
 temperature,
     ' and fuel cell current
     Set normalgraph = Charts.Add
     Set normalgraph = normalgraph.Location(whe=xlLocationAsObject,
 Name:=wsname)
     ngName = normalgraph.Name
 
     'more code

Thanks!



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
can't active chart [email protected] Charts and Charting in Excel 0 September 15th 07 07:05 PM
Chart & Active Sheet Ardy Excel Programming 2 February 9th 07 01:00 PM
active chart- please help Rob Charts and Charting in Excel 1 April 27th 05 03:08 AM
Dynamically chart active row Patti Charts and Charting in Excel 7 April 4th 05 03:39 PM
How to embed chart in active worksheet with VBA? deko[_2_] Excel Programming 9 March 4th 05 05:39 AM


All times are GMT +1. The time now is 08:09 PM.

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

About Us

"It's about Microsoft Excel"