Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Selection with one object

I have a macro that lets the user first select a number of charts and then
when the user presses a button the charts sizes and color are eing changed.
The problem is that it does not works if I only have one chart selected. When
I have two or more it works fine. My code (relevant parts) is:

Public Sub arrayLoop()
Dim obj As Object
Dim currentChart As Object

For Each obj In Selection
If TypeName(obj) = "ChartObject" Then
Set currentChart = obj
Call linjeDiagramKnapp(currentChart)
End If
Next
End Sub

In this sub I check the selection to see if the selected objects really are
charts. I assume that there is something wrong here on the first line of the
For-loop, but I do not know how it should be or if the problem might be
elsewhere. Any help appreciated! Thanks alot!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default Selection with one object

Expand the code a little more to check TypeName of selection.

Public Sub arrayLoop()
Dim obj As Object
Dim currentChart As Object

If TypeName(Selection) = "DrawingObjects" Then
' group of possible charts
For Each obj In Selection
If TypeName(obj) = "ChartObject" Then
Set currentChart = obj
Call linjeDiagramKnapp(currentChart)
End If
Next
ElseIf TypeName(Selection) = "ChartObject" Then
' single chartobject
Set currentChart = Selection
Call linjeDiagramKnapp(currentChart)
ElseIf TypeName(Selection) = "ChartArea" Then
' activechart
Set currentChart = Selection.Parent
Call linjeDiagramKnapp(currentChart)
End If

End Sub

Cheers
Andy

Arne Hegefors wrote:
I have a macro that lets the user first select a number of charts and then
when the user presses a button the charts sizes and color are eing changed.
The problem is that it does not works if I only have one chart selected. When
I have two or more it works fine. My code (relevant parts) is:

Public Sub arrayLoop()
Dim obj As Object
Dim currentChart As Object

For Each obj In Selection
If TypeName(obj) = "ChartObject" Then
Set currentChart = obj
Call linjeDiagramKnapp(currentChart)
End If
Next
End Sub

In this sub I check the selection to see if the selected objects really are
charts. I assume that there is something wrong here on the first line of the
For-loop, but I do not know how it should be or if the problem might be
elsewhere. Any help appreciated! Thanks alot!


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Selection with one object

Hi Andy! Your code works fine but it creates another problem. When I pass the
chart(s) along to another sub as an argument that sub does not quite know
what type of object it is. It seems like that at least because when I try to
make changes to the charts in the sub I get an error either way I write it
depending on if I have selected one or two charts. In the sub:

Sub linjeDiagramKnapp(argChart As Object)

if I write: With argChart.Chart
i get error if I have selected only one chart but it works fine if I have
selected two charts. If i write:
with argChart
and i only have one chart selected it works fine but with two charts i get
error. do you have any idea of how to solve that probelm? any help
appreciated!

"Andy Pope" skrev:

Expand the code a little more to check TypeName of selection.

Public Sub arrayLoop()
Dim obj As Object
Dim currentChart As Object

If TypeName(Selection) = "DrawingObjects" Then
' group of possible charts
For Each obj In Selection
If TypeName(obj) = "ChartObject" Then
Set currentChart = obj
Call linjeDiagramKnapp(currentChart)
End If
Next
ElseIf TypeName(Selection) = "ChartObject" Then
' single chartobject
Set currentChart = Selection
Call linjeDiagramKnapp(currentChart)
ElseIf TypeName(Selection) = "ChartArea" Then
' activechart
Set currentChart = Selection.Parent
Call linjeDiagramKnapp(currentChart)
End If

End Sub

Cheers
Andy

Arne Hegefors wrote:
I have a macro that lets the user first select a number of charts and then
when the user presses a button the charts sizes and color are eing changed.
The problem is that it does not works if I only have one chart selected. When
I have two or more it works fine. My code (relevant parts) is:

Public Sub arrayLoop()
Dim obj As Object
Dim currentChart As Object

For Each obj In Selection
If TypeName(obj) = "ChartObject" Then
Set currentChart = obj
Call linjeDiagramKnapp(currentChart)
End If
Next
End Sub

In this sub I check the selection to see if the selected objects really are
charts. I assume that there is something wrong here on the first line of the
For-loop, but I do not know how it should be or if the problem might be
elsewhere. Any help appreciated! Thanks alot!


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default Selection with one object

Now I can see the header for linjeDiagramKnapp routine I can see that
the activechart part is not quite right. Needs another Parent reference
in order to pass the same object level as the others.

Try this modification.


' activechart
Set currentChart = Selection.Parent.Parent
Call linjeDiagramKnapp(currentChart)


This is what I used to test the various selections.

Sub linjeDiagramKnapp(argChart As Object)

With argChart.Chart
MsgBox "Has " & .SeriesCollection.Count & " series"
End With

End Sub

Cheers
Andy

Arne Hegefors wrote:
Hi Andy! Your code works fine but it creates another problem. When I pass the
chart(s) along to another sub as an argument that sub does not quite know
what type of object it is. It seems like that at least because when I try to
make changes to the charts in the sub I get an error either way I write it
depending on if I have selected one or two charts. In the sub:

Sub linjeDiagramKnapp(argChart As Object)

if I write: With argChart.Chart
i get error if I have selected only one chart but it works fine if I have
selected two charts. If i write:
with argChart
and i only have one chart selected it works fine but with two charts i get
error. do you have any idea of how to solve that probelm? any help
appreciated!

"Andy Pope" skrev:


Expand the code a little more to check TypeName of selection.

Public Sub arrayLoop()
Dim obj As Object
Dim currentChart As Object

If TypeName(Selection) = "DrawingObjects" Then
' group of possible charts
For Each obj In Selection
If TypeName(obj) = "ChartObject" Then
Set currentChart = obj
Call linjeDiagramKnapp(currentChart)
End If
Next
ElseIf TypeName(Selection) = "ChartObject" Then
' single chartobject
Set currentChart = Selection
Call linjeDiagramKnapp(currentChart)
ElseIf TypeName(Selection) = "ChartArea" Then
' activechart
Set currentChart = Selection.Parent
Call linjeDiagramKnapp(currentChart)
End If

End Sub

Cheers
Andy

Arne Hegefors wrote:

I have a macro that lets the user first select a number of charts and then
when the user presses a button the charts sizes and color are eing changed.
The problem is that it does not works if I only have one chart selected. When
I have two or more it works fine. My code (relevant parts) is:

Public Sub arrayLoop()
Dim obj As Object
Dim currentChart As Object

For Each obj In Selection
If TypeName(obj) = "ChartObject" Then
Set currentChart = obj
Call linjeDiagramKnapp(currentChart)
End If
Next
End Sub

In this sub I check the selection to see if the selected objects really are
charts. I assume that there is something wrong here on the first line of the
For-loop, but I do not know how it should be or if the problem might be
elsewhere. Any help appreciated! Thanks alot!


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
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
Object Selection W2 Excel Discussion (Misc queries) 2 August 26th 08 06:07 PM
Object Variable Not Set Error on Selection object Jean Excel Worksheet Functions 3 July 24th 06 06:45 PM
Object Type of a selection... counting rows in a selection Acid-Sky[_2_] Excel Programming 3 August 23rd 05 09:53 AM
Selection object in Excel 2002 Franco22 Excel Programming 2 April 29th 04 09:36 PM
Method selection of object _Global falied Leon[_3_] Excel Programming 2 December 24th 03 12:44 AM


All times are GMT +1. The time now is 02:14 AM.

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"