Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Chart formatting - CommandButton

Hello,

I wrote the following code aiming to format different parameters in a chart.
The purpose is to run the macro after having selected a chart in the
worksheet (ie the one you specifically want to change) .

---------------------------------
Sub InsideChartFormat()
'
'05/10/2004 - rvg
'
ActiveChart.ChartArea.Select
Selection.AutoScaleFont = False
With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
'Plot Area
ActiveChart.PlotArea.Select
Selection.Left = 1
Selection.Top = 10
Selection.Width = 600
Selection.Height = 650
'Legend
ActiveChart.Legend.Select
With Selection
.Top = 40
.Left = 50
.Width = 120
.Height = 50
End With
End Sub
-----------------------------------

Everything worked perfectly... but I tried to assign the macro to a
CommandButton. Then, my problem is as follow : after having selected my
chart, I click on the CommnandButton. The routine starts, then stops with an
'91' error type. Could someone help me to fix this ?!

Acheron

PS : I guess that clicking on the CommandButton has an impact such as
deselecting the chart or changing it into a Shape object instead of a
ChartObject ... but I'm stuck. Note that using a CommandButton is really,
really convenient. Putting an extra button in a toolbar is not an option,
considering that I have about 12 different types of charts in my sheet
requiring different formatting. Consequently, to be 'user friendly', I need
to put a CommandButton next to each type of chart (a type can include a few
charts, but not all of them need to be re-formatted, reason why the user must
have the choice to select a specific chart ).
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Chart formatting - CommandButton

Change the Takefocusonclick property of the commandbutton to false.

--
Regards,
Tom Ogilvy

"Acheron" wrote in message
...
Hello,

I wrote the following code aiming to format different parameters in a

chart.
The purpose is to run the macro after having selected a chart in the
worksheet (ie the one you specifically want to change) .

---------------------------------
Sub InsideChartFormat()
'
'05/10/2004 - rvg
'
ActiveChart.ChartArea.Select
Selection.AutoScaleFont = False
With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
'Plot Area
ActiveChart.PlotArea.Select
Selection.Left = 1
Selection.Top = 10
Selection.Width = 600
Selection.Height = 650
'Legend
ActiveChart.Legend.Select
With Selection
.Top = 40
.Left = 50
.Width = 120
.Height = 50
End With
End Sub
-----------------------------------

Everything worked perfectly... but I tried to assign the macro to a
CommandButton. Then, my problem is as follow : after having selected my
chart, I click on the CommnandButton. The routine starts, then stops with

an
'91' error type. Could someone help me to fix this ?!

Acheron

PS : I guess that clicking on the CommandButton has an impact such as
deselecting the chart or changing it into a Shape object instead of a
ChartObject ... but I'm stuck. Note that using a CommandButton is really,
really convenient. Putting an extra button in a toolbar is not an option,
considering that I have about 12 different types of charts in my sheet
requiring different formatting. Consequently, to be 'user friendly', I

need
to put a CommandButton next to each type of chart (a type can include a

few
charts, but not all of them need to be re-formatted, reason why the user

must
have the choice to select a specific chart ).



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Chart formatting - CommandButton

Thanks Tom... but I am afraid that this is not the solution. The error type
changed (and is now '1004' instead of '91')... It is more frustrating knowing
that, when I run the macro from the Visual Basic toolbar... everything works
properly... aaaarghhhhh....

"Tom Ogilvy" wrote:

Change the Takefocusonclick property of the commandbutton to false.

--
Regards,
Tom Ogilvy

"Acheron" wrote in message
...
Hello,

I wrote the following code aiming to format different parameters in a

chart.
The purpose is to run the macro after having selected a chart in the
worksheet (ie the one you specifically want to change) .

---------------------------------
Sub InsideChartFormat()
'
'05/10/2004 - rvg
'
ActiveChart.ChartArea.Select
Selection.AutoScaleFont = False
With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
'Plot Area
ActiveChart.PlotArea.Select
Selection.Left = 1
Selection.Top = 10
Selection.Width = 600
Selection.Height = 650
'Legend
ActiveChart.Legend.Select
With Selection
.Top = 40
.Left = 50
.Width = 120
.Height = 50
End With
End Sub
-----------------------------------

Everything worked perfectly... but I tried to assign the macro to a
CommandButton. Then, my problem is as follow : after having selected my
chart, I click on the CommnandButton. The routine starts, then stops with

an
'91' error type. Could someone help me to fix this ?!

Acheron

PS : I guess that clicking on the CommandButton has an impact such as
deselecting the chart or changing it into a Shape object instead of a
ChartObject ... but I'm stuck. Note that using a CommandButton is really,
really convenient. Putting an extra button in a toolbar is not an option,
considering that I have about 12 different types of charts in my sheet
requiring different formatting. Consequently, to be 'user friendly', I

need
to put a CommandButton next to each type of chart (a type can include a

few
charts, but not all of them need to be re-formatted, reason why the user

must
have the choice to select a specific chart ).




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Chart formatting - CommandButton

I wouldn't say that isn't the solution to the problem you described. After
all, it changed the error. That doesn't mean you don't have more problems
in you code. Try putting all the code back in a general module and then
call it from your event code.

Private Sub Commandbutton_Click()
InsideChartformat
End Sub

the InsideChartFormat should be in a general module, not in a sheet module
or the thisworkbook module or a userform module.

--
Regards,
Tom Ogilvy

"Acheron" wrote in message
...
Thanks Tom... but I am afraid that this is not the solution. The error

type
changed (and is now '1004' instead of '91')... It is more frustrating

knowing
that, when I run the macro from the Visual Basic toolbar... everything

works
properly... aaaarghhhhh....

"Tom Ogilvy" wrote:

Change the Takefocusonclick property of the commandbutton to false.

--
Regards,
Tom Ogilvy

"Acheron" wrote in message
...
Hello,

I wrote the following code aiming to format different parameters in a

chart.
The purpose is to run the macro after having selected a chart in the
worksheet (ie the one you specifically want to change) .

---------------------------------
Sub InsideChartFormat()
'
'05/10/2004 - rvg
'
ActiveChart.ChartArea.Select
Selection.AutoScaleFont = False
With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
'Plot Area
ActiveChart.PlotArea.Select
Selection.Left = 1
Selection.Top = 10
Selection.Width = 600
Selection.Height = 650
'Legend
ActiveChart.Legend.Select
With Selection
.Top = 40
.Left = 50
.Width = 120
.Height = 50
End With
End Sub
-----------------------------------

Everything worked perfectly... but I tried to assign the macro to a
CommandButton. Then, my problem is as follow : after having selected

my
chart, I click on the CommnandButton. The routine starts, then stops

with
an
'91' error type. Could someone help me to fix this ?!

Acheron

PS : I guess that clicking on the CommandButton has an impact such as
deselecting the chart or changing it into a Shape object instead of a
ChartObject ... but I'm stuck. Note that using a CommandButton is

really,
really convenient. Putting an extra button in a toolbar is not an

option,
considering that I have about 12 different types of charts in my sheet
requiring different formatting. Consequently, to be 'user friendly', I

need
to put a CommandButton next to each type of chart (a type can include

a
few
charts, but not all of them need to be re-formatted, reason why the

user
must
have the choice to select a specific chart ).






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Chart formatting - CommandButton

Hi,

I checked my code... everything seems ok according to your remark (right
place, right module, etc). So the problem doesn't come from there.

I thought that I could, maybe try to specify the name of the chart,
rewriting the beginning of the routine as follow :

Dim chrtnme As String
chrtname = ActiveChart.Name
' display the Chart name to ensure it's the good one.
MsgBox chrtname
' Activate the selected chart
ActiveSheet.ChartObjects(chrtname).Activate

.... but once again... error (1004) (I tried even with the chrtname between
brackets). The Chart name is correctly displayed in the MsgBox. But the
routine stops at the following line.

I know that's something is going wrong with this code (and I have to
recognize that I'm quite a beginner in VBA...) so... if you can help, you're
always welcome !!!

"Tom Ogilvy" wrote:

I wouldn't say that isn't the solution to the problem you described. After
all, it changed the error. That doesn't mean you don't have more problems
in you code. Try putting all the code back in a general module and then
call it from your event code.

Private Sub Commandbutton_Click()
InsideChartformat
End Sub

the InsideChartFormat should be in a general module, not in a sheet module
or the thisworkbook module or a userform module.

--
Regards,
Tom Ogilvy

"Acheron" wrote in message
...
Thanks Tom... but I am afraid that this is not the solution. The error

type
changed (and is now '1004' instead of '91')... It is more frustrating

knowing
that, when I run the macro from the Visual Basic toolbar... everything

works
properly... aaaarghhhhh....

"Tom Ogilvy" wrote:

Change the Takefocusonclick property of the commandbutton to false.

--
Regards,
Tom Ogilvy

"Acheron" wrote in message
...
Hello,

I wrote the following code aiming to format different parameters in a
chart.
The purpose is to run the macro after having selected a chart in the
worksheet (ie the one you specifically want to change) .

---------------------------------
Sub InsideChartFormat()
'
'05/10/2004 - rvg
'
ActiveChart.ChartArea.Select
Selection.AutoScaleFont = False
With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
'Plot Area
ActiveChart.PlotArea.Select
Selection.Left = 1
Selection.Top = 10
Selection.Width = 600
Selection.Height = 650
'Legend
ActiveChart.Legend.Select
With Selection
.Top = 40
.Left = 50
.Width = 120
.Height = 50
End With
End Sub
-----------------------------------

Everything worked perfectly... but I tried to assign the macro to a
CommandButton. Then, my problem is as follow : after having selected

my
chart, I click on the CommnandButton. The routine starts, then stops

with
an
'91' error type. Could someone help me to fix this ?!

Acheron

PS : I guess that clicking on the CommandButton has an impact such as
deselecting the chart or changing it into a Shape object instead of a
ChartObject ... but I'm stuck. Note that using a CommandButton is

really,
really convenient. Putting an extra button in a toolbar is not an

option,
considering that I have about 12 different types of charts in my sheet
requiring different formatting. Consequently, to be 'user friendly', I
need
to put a CommandButton next to each type of chart (a type can include

a
few
charts, but not all of them need to be re-formatted, reason why the

user
must
have the choice to select a specific chart ).








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Chart formatting - CommandButton

The name of the chart is not the argument to ChartObjects, so no wonder you
are getting an error.

for each chtObj in Activesheet.ChartObject
msgbox chtObj.Name & " <-- " & chtObj.Chart.Name
Next

to illustrate.

But you have already said your code worked when it was in a general module.
Now you say it doesn't.
Everything worked perfectly... but I tried to assign the macro to a
CommandButton.


So saying you checked your code . . .

--
Regards,
Tom Ogilvy


"Acheron" wrote in message
...
Hi,

I checked my code... everything seems ok according to your remark (right
place, right module, etc). So the problem doesn't come from there.

I thought that I could, maybe try to specify the name of the chart,
rewriting the beginning of the routine as follow :

Dim chrtnme As String
chrtname = ActiveChart.Name
' display the Chart name to ensure it's the good one.
MsgBox chrtname
' Activate the selected chart
ActiveSheet.ChartObjects(chrtname).Activate

... but once again... error (1004) (I tried even with the chrtname between
brackets). The Chart name is correctly displayed in the MsgBox. But the
routine stops at the following line.

I know that's something is going wrong with this code (and I have to
recognize that I'm quite a beginner in VBA...) so... if you can help,

you're
always welcome !!!

"Tom Ogilvy" wrote:

I wouldn't say that isn't the solution to the problem you described.

After
all, it changed the error. That doesn't mean you don't have more

problems
in you code. Try putting all the code back in a general module and then
call it from your event code.

Private Sub Commandbutton_Click()
InsideChartformat
End Sub

the InsideChartFormat should be in a general module, not in a sheet

module
or the thisworkbook module or a userform module.

--
Regards,
Tom Ogilvy

"Acheron" wrote in message
...
Thanks Tom... but I am afraid that this is not the solution. The error

type
changed (and is now '1004' instead of '91')... It is more frustrating

knowing
that, when I run the macro from the Visual Basic toolbar... everything

works
properly... aaaarghhhhh....

"Tom Ogilvy" wrote:

Change the Takefocusonclick property of the commandbutton to false.

--
Regards,
Tom Ogilvy

"Acheron" wrote in message
...
Hello,

I wrote the following code aiming to format different parameters

in a
chart.
The purpose is to run the macro after having selected a chart in

the
worksheet (ie the one you specifically want to change) .

---------------------------------
Sub InsideChartFormat()
'
'05/10/2004 - rvg
'
ActiveChart.ChartArea.Select
Selection.AutoScaleFont = False
With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
'Plot Area
ActiveChart.PlotArea.Select
Selection.Left = 1
Selection.Top = 10
Selection.Width = 600
Selection.Height = 650
'Legend
ActiveChart.Legend.Select
With Selection
.Top = 40
.Left = 50
.Width = 120
.Height = 50
End With
End Sub
-----------------------------------

Everything worked perfectly... but I tried to assign the macro to

a
CommandButton. Then, my problem is as follow : after having

selected
my
chart, I click on the CommnandButton. The routine starts, then

stops
with
an
'91' error type. Could someone help me to fix this ?!

Acheron

PS : I guess that clicking on the CommandButton has an impact such

as
deselecting the chart or changing it into a Shape object instead

of a
ChartObject ... but I'm stuck. Note that using a CommandButton is

really,
really convenient. Putting an extra button in a toolbar is not an

option,
considering that I have about 12 different types of charts in my

sheet
requiring different formatting. Consequently, to be 'user

friendly', I
need
to put a CommandButton next to each type of chart (a type can

include
a
few
charts, but not all of them need to be re-formatted, reason why

the
user
must
have the choice to select a specific chart ).








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
Link embedded chart to a commandbutton? Bob Charts and Charting in Excel 7 June 19th 09 02:01 PM
CommandButton Alvin Hansen[_2_] Excel Programming 3 August 16th 04 06:35 PM
CommandButton chris[_12_] Excel Programming 1 April 15th 04 01:01 AM
CommandButton rwebster3 Excel Programming 0 April 14th 04 08:16 PM
Commandbutton David Fixemer Excel Programming 2 February 25th 04 10:18 PM


All times are GMT +1. The time now is 12:55 PM.

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

About Us

"It's about Microsoft Excel"