View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Argument not optional

What line is highlighted when you hit debug after you get the error message?

--
Regards,
Tom Ogilvy


"Arne Hegefors" wrote:

Hello (again)! I am really having big trouble with a seemingly easy
application. I have some buttons that when pressed changes selected charts so
that they look a certain way. I have two buttons and the code for the two
different buttons, one is working fine but the other gives me the error
message "Argument not optional" (as I had not selected any charts but I
have). The strange thing is that the codes for the two buttons are basically
xeroxed from each other ie none or both should give error. I cannot
understand why this is the case. The code for the two buttons is:

Set linjeDiagramKnapp = .Controls.Add(Type:=msoControlButton)
With linjeDiagramKnapp
.Caption = "Linjediagram"
.Style = msoButtonCaption
''' msoButtonAutomatic, msoButtonIcon, msoButtonCaption,
''' or msoButtonIconandCaption
.BeginGroup = True
.OnAction = "ChartModul1.arrayLoop"
End With
'slut linjediagramknapp

'stapeldiagramknapp
Set stapelDiagramKnapp = .Controls.Add(Type:=msoControlButton)
With stapelDiagramKnapp
.Caption = "Stapeldiagram"
.Style = msoButtonCaption
''' msoButtonAutomatic, msoButtonIcon, msoButtonCaption,
''' or msoButtonIconandCaption
.BeginGroup = True
.OnAction = "ChartModul2.arrayLoops"
End With
'slut stapeldiagramknapp

and their respective subs are (first a loop that checks to see if selected
objects truly are charts, thanks very much to NickHK and everybody else who
patiently helped me with this).

Sub arrayLoops()
Dim obj As Object
Dim currentChart As Object

'loopar igenom de selekterade objekten. om ett objekt är en Chart så
'skickas det vidare till Sub stapelDiagramKnapp.
For Each obj In Selection
If TypeName(obj) = "ChartObject" Then
Set currentChart = obj
Call stapelDiagramKnapp(currentChart) 'skickar Chart
End If
Next
'slut på loop
End Sub

Sub stapelDiagramKnapp(argChart As Object)

Dim mySize As Double
With argChart.Chart
'här börjar inställningen för chart
.ApplyCustomType ChartType:=xlUserDefined, TypeName:="Standard"

With argChart
.Height = 150
.Width = 150
.Top = 100
.Left = 100
End With
.......
end sub

and the other one:

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

'loopar igenom de selekterade objekten. om ett objekt är en Chart så
'skickas det vidare till Sub linjeDiagramKnapp.
For Each obj In Selection
If TypeName(obj) = "ChartObject" Then
Set currentChart = obj
Call linjeDiagramKnapp(currentChart) 'skickar Chart
End If
Next
'slut på loop
End Sub

Sub linjeDiagramKnapp(argChart As Object)

Dim mySize As Double
With argChart.Chart
'här börjar inställningen för chart
.ApplyCustomType ChartType:=xlUserDefined, TypeName:="Standard"

With argChart
.Height = 150
.Width = 150
.Top = 100
.Left = 100
End With
.....
end sub.

The one called stapeldiagram gives me the error message "Argument not
optional" but it works if you go into the code and use "F8" to walk through
the lines.... Perhaps it is not possible to see in the code what is wrong but
I have selected the charts and I cannot figure out what is wrong. PLease help
me out! I know I am a pain but I really dont understand why i am having such
trouble with this...(perhaps because I really suck at coding I guess). I
would very much appreciate any help I can get! Thank you all very much for
all your help!!