Chartobjects(n).Select

delpiero

New Member
Joined
Jul 21, 2010
Messages
4
Warum funktioniert "Chartobjects(n).Select"nicht?

das ist mein gesamter code


Option Explicit
Private Sub ScrollBar()
Dim ScrollBar As String
Dim chartname As String
Dim a, a1 As Integer
Dim b, b1 As Integer
Dim x1 As Integer
Dim x2 As Integer
Dim nMaxZeilen As Integer
Dim NewFileName() As String
Dim Min As Double
Dim Max As Double
Dim Chart As String
Dim sheetname As String
Chart = "Chart 1"
Dim Counter As Integer
Dim nMaxZeilen2 As String
Dim varname1, varname2 As String
varname1 = "scrolmin"
varname2 = "scrolmax"
Dim chtobj As ChartObject
Dim Msg As String
Dim n As Integer
Dim ws As Worksheet
Dim iiii As Integer
Dim cht_width As Integer
Dim cht_height As Integer
Dim Top_Position As Integer
Dim Left_Position As Integer
Dim k As Integer


iiii = 1

For Each ws In ActiveWorkbook.Worksheets
n = ws.Chartobjects.Count
'Msg = "Chart List for Sheet " & vbTab & ws.Name & vbTab & _
' "No charts = " & n & vbCrLf & vbCrLf
'Msg = Msg & "Name " & vbTab & vbTab & "Index" & vbTab & "Top Pos" & _
' vbTab & "Left Pos " & vbTab & "Width " & vbTab & "Height" & vbCrLf



Do While k <= n
k = k + 1
Chartobjects(n).Select
ActiveSheet.ChartObject(1).Active
Counter = 1
chartname = ActiveChart.Name

If chartname = "" Then 'überarbeiten weil ich es nicht nochmal machen will ... rest morgen... *gg*
MsgBox "Kein Diagrammm ausgewählt!!!"
Else

NewFileName = Split(chartname, " ")
sheetname = NewFileName(0)
chartname = NewFileName(1) & " " & NewFileName(2)
End If
If Counter = Empty Then
MsgBox "incorrect!!!"
Exit Sub
End If
Chart = Chart & Counter

If Not ActiveChart.Name = "" Then

Range("a:a").Select
nMaxZeilen = ActiveSheet.UsedRange.Rows.Count

nMaxZeilen2 = nMaxZeilen

Range("a" & nMaxZeilen + 1) = "=min(a4:a" & nMaxZeilen & ")"
a = Range("a" & nMaxZeilen + 1)
Range("a" & nMaxZeilen + 1).Delete

ActiveSheet.ScrollBars.Add(60, 50, 450, 20).Name = varname1
ActiveSheet.ScrollBars(varname1).Select

With Selection 'von min bis x1
.value = Range("II1") ' = variable durch schieber definiert!!!
.Min = a ' = a
.Max = b ' = x2
.SmallChange = 1
.LargeChange = 10
.LinkedCell = "$II$1"
.Display3DShading = True

End With


ActiveSheet.ScrollBars.Add(60, 70, 450, 20).Name = varname2
ActiveSheet.ScrollBars(varname2).Select

With Selection
.value = Range("II2")
.Min = a
.Max = b
.SmallChange = 1
.LargeChange = 10
.LinkedCell = "$II$2"
.Display3DShading = True

End With

a = Range("II1")
b = Range("II2")

ActiveSheet.Chartobjects(chartname).Activate

With ActiveChart.Axes(xlCategory)
.MinimumScale = a '=a
.MaximumScale = b '=b
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
.HasTitle = True
.AxisTitle.Characters.Text = "Time "
End With


Else
MsgBox "kein Chart ausgewählt!!!"
End If

For Each chtobj In ActiveSheet.Chartobjects
cht_width = chtobj.Width
cht_height = chtobj.Height
Top_Position = chtobj.Top
Left_Position = chtobj.Left
iiii = iiii + 1
Loop
Next 'chtobj
Next 'ws

'out = MsgBox(Msg, , "Chart List")

End Sub

vielen dank im vorraus
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
  1. Please use code tags when posting code. It makes it much easier to read your code.
  2. Please use proper indentation to express the logical organization of your code (the board will remove this if you do not use code tags).
  3. Please see the changes I made to your code. I did not run past the If Not ActiveChart.Name = "" Then line of code however this should get you started towards what you want.
  4. Please be aware that it is very rarely necessary (or recommended) that you SELECT an object. You are better off creating a variable of the type you need to manipulate and then SETting your variable to that object. This allows for early binding and help from Intellisense. Using the SELECTION object prevents any help from Intellisense.
  5. Also, I would avoid using variable names that are also keywords: such as SCROLLBAR, MAX or MIN.
[translation done by Google, I apologize but my German is even worse than Google's]

  1. Tags verwenden Code Bitte Code bei der Buchung. Es macht es viel Ihr Code leichter zu lesen.
  2. Bitte benutzen Sie richtige Einrückung auf die logische Organisation des Codes (das Brett Express wird dies, wenn Sie nicht Code-Tags entfernen ).
  3. Bitte beachten Sie die Änderungen, die ich um Ihren Code vorgenommen. Ich habe nicht die Vergangenheit Wenn nicht ActiveChart.Name = "" Then Codezeile ausführen dies sollte jedoch Ihnen den Einstieg zu dem, was Sie wollen.
  4. Bitte bewusst sein, dass es nur sehr selten notwendig ist (oder empfohlen), dass Sie ein Objekt auswählen. Du bist besser dran, schaffen eine Variable des Typs Sie benötigen, um zu manipulieren und dann Einstellen Ihrer Variable auf das Objekt. Dies ermöglicht die frühe Bindung und Unterstützung von IntelliSense. Mit dem Selection-Objekt verhindert jegliche Hilfe von IntelliSense.
  5. Auch würde ich nicht benutzen Variablennamen, die auch Stichwort: wie Scrollbar, MAX oder MIN.
Code:
Private Sub ScrollBarz()
Dim ScrollBar As String
Dim chartname As String
Dim a, a1 As Integer
Dim b, b1 As Integer
Dim x1 As Integer
Dim x2 As Integer
Dim nMaxZeilen As Integer
Dim NewFileName() As String
Dim Min As Double
Dim Max As Double
Dim Chart As String
Dim sheetname As String
Chart = "Chart 1"
Dim Counter As Integer
Dim nMaxZeilen2 As String
Dim varname1, varname2 As String
varname1 = "scrolmin"
varname2 = "scrolmax"
Dim chtobj As ChartObject
Dim Msg As String
Dim n As Integer
Dim ws As Worksheet
Dim iiii As Integer
Dim cht_width As Integer
Dim cht_height As Integer
Dim Top_Position As Integer
Dim Left_Position As Integer
Dim k As Integer
 
iiii = 1
For Each ws In ActiveWorkbook.Worksheets
    n = ws.ChartObjects.Count
    'Msg = "Chart List for Sheet " & vbTab & ws.Name & vbTab & _
    ' "No charts = " & n & vbCrLf & vbCrLf
    'Msg = Msg & "Name " & vbTab & vbTab & "Index" & vbTab & "Top Pos" & _
    ' vbTab & "Left Pos " & vbTab & "Width " & vbTab & "Height" & vbCrLf
    k = 0
    Do While k < n
        k = k + 1
        ActiveSheet.ChartObjects(n).Select
'        ActiveSheet.ChartObject(1).Activate
        Counter = 1
        chartname = ActiveChart.Name
 
        If chartname = "" Then 'überarbeiten weil ich es nicht nochmal machen will ... rest morgen... *gg*
            MsgBox "Kein Diagrammm ausgewählt!!!"
        Else
 
            NewFileName = Split(chartname, " ")
            sheetname = NewFileName(0)
            chartname = NewFileName(1) & " " & NewFileName(2)
        End If
 
        If Counter = Empty Then
            MsgBox "incorrect!!!"
            Exit Sub
        End If
 
        Chart = Chart & Counter
 
        If Not ActiveChart.Name = "" Then
 
            Range("a:a").Select
            nMaxZeilen = ActiveSheet.UsedRange.Rows.Count
 
            nMaxZeilen2 = nMaxZeilen
 
            Range("a" & nMaxZeilen + 1) = "=min(a4:a" & nMaxZeilen & ")"
            a = Range("a" & nMaxZeilen + 1)
            Range("a" & nMaxZeilen + 1).Delete
 
            ActiveSheet.ScrollBars.Add(60, 50, 450, 20).Name = varname1
            ActiveSheet.ScrollBars(varname1).Select
 
            With Selection 'von min bis x1
                .Value = Range("II1") ' = variable durch schieber definiert!!!
                .Min = a ' = a
                .Max = b ' = x2
                .SmallChange = 1
                .LargeChange = 10
                .LinkedCell = "$II$1"
                .Display3DShading = True
            End With
 
 
            ActiveSheet.ScrollBars.Add(60, 70, 450, 20).Name = varname2
            ActiveSheet.ScrollBars(varname2).Select
 
            With Selection
                .Value = Range("II2")
                .Min = a
                .Max = b
                .SmallChange = 1
                .LargeChange = 10
                .LinkedCell = "$II$2"
                .Display3DShading = True
            End With
 
            a = Range("II1")
            b = Range("II2")
 
            ActiveSheet.ChartObjects(chartname).Activate
 
            With ActiveChart.Axes(xlCategory)
                .MinimumScale = a '=a
                .MaximumScale = b '=b
                .MinorUnitIsAuto = True
                .MajorUnitIsAuto = True
                .Crosses = xlAutomatic
                .ReversePlotOrder = False
                .ScaleType = xlLinear
                .DisplayUnit = xlNone
                .HasTitle = True
                .AxisTitle.Characters.Text = "Time [s]"
            End With
 
 
        Else
            MsgBox "kein Chart ausgewählt!!!"
        End If  '// activechart.name = ""
 
        For Each chtobj In ActiveSheet.ChartObjects
            cht_width = chtobj.Width
            cht_height = chtobj.Height
            Top_Position = chtobj.Top
            Left_Position = chtobj.Left
            iiii = iiii + 1
        Next 'chtobj
    Loop '// do while k <= n
Next 'ws
'out = MsgBox(Msg, , "Chart List")
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,629
Members
452,661
Latest member
Nonhle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top