+ Reply to Thread
Results 1 to 16 of 16

Shapes works in one workbook but not another

Hybrid View

  1. #1
    Registered User
    Join Date
    11-26-2009
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2019
    Posts
    46

    Shapes works in one workbook but not another

    I've designed a procedure that, via shapes, draws a beam and the forces acting on the beam.
    Depending on the size of the beam, the size and placement of the forces etc. the procedure places and sizes the beam and forzes correspondingly.

    I've originally made this procedure on a blank workbook just to get the drawingprocedure in place and it works fine.

    But when i copy the procedure into the workbook containing the beamcalculations errors occur and only some of the shapes are drawn (i've mad sure that all the input referencecells are updated).

    Here is some of the original code that works fine as a stand-alone with corresponding inputdata from the following cells. When i copy the code into the other workbook i get the first error in this part of the code:

       mySheet.Shapes.AddLine(RYKIND, RYKNED, RYKIND + BJÆLKELÆNGDE, RYKNED).Select 'her tegnes bjælke
        Selection.ShapeRange.Line.Weight = 6#
        Selection.ShapeRange.Line.Visible = msoTrue
        Selection.ShapeRange.Line.Style = msoLineSingleSelection.ShapeRange.Name = "bjælke"
    I get the first errror in the line.style-statement:

    "Run time error '-2147024809 (80070057)': the stated value is outside the limits"

    or

    "Run time error "438": Object doesn't support this property or method"



    Here is a larger part of the code.

    I get a lot of similar errors working down the code

     sub tegne()
    
    Set mySheet = activeSheet
    Dim sh As Shape
    Dim pdlinie As Single, P1 As Single, P2 As Single, x1 As Single, x2 As Single, M1 As Single, M2 As Single
    Dim totallast As Single, pdlinieHøjde As Single, P1Højde As Single, P2Højde As Single, x1Længde As Single
    Dim x2Længde As Single, længde As Single, afstand As Single
    Dim tæller As Byte
    Dim P1tekstplacering As Integer, P2tekstplacering As Integer, flytbidragP1 As Integer, flytbidragP2 As Integer
    Dim P1HøjdeTillæg As Integer, P2HøjdeTillæg As Integer
    
    Const BJÆLKELÆNGDE As Integer = 275
    Const RYKIND As Integer = 75
    Const RYKNED As Integer = 200
    Const MAXLASTHØJDE As Integer = 80
    Const STEPS As Byte = 15 'må højst vælges til 20
    
    afstand = BJÆLKELÆNGDE / STEPS
    
    længde = Range("B24").Value
    pdlinie = Range("B26").Value
    P1 = Range("B27").Value
    P2 = Range("B28").Value
    x1 = Range("B29").Value
    x2 = Range("B30").Value
    M1 = Range("B31").Value
    M2 = Range("B32").Value
    
    If P1 >= P2 Then
        totallast = pdlinie + P1
    Else: totallast = pdlinie + P2
    End If
            
    pdlinieHøjde = pdlinie * MAXLASTHØJDE / totallast
    P1Højde = P1 * MAXLASTHØJDE / totallast
    If P1Højde < 0.2 * MAXLASTHØJDE Then
        P1HøjdeTillæg = 0.2 * MAXLASTHØJDE
        P1Højde = 0.1 * MAXLASTHØJDE
    Else: P1HøjdeTillæg = P1Højde
    End If
    P2Højde = P2 * MAXLASTHØJDE / totallast
    If P2Højde < 0.2 * MAXLASTHØJDE Then
        P2HøjdeTillæg = 0.2 * MAXLASTHØJDE
        P2Højde = 0.1 * MAXLASTHØJDE
    Else: P2HøjdeTillæg = P2Højde
    End If
    
    x1Længde = x1 * BJÆLKELÆNGDE / længde
    x2Længde = x2 * BJÆLKELÆNGDE / længde
    
    With mySheet 'Her renses arket for gamle shapes
       For Each sh In .Shapes
            If sh.Name = "bjælke" Or sh.Name = "venstre" Or sh.Name = "højre" Or sh.Name = "mållinie" Or sh.Name = "pdlinie" Then
                sh.Delete
            ElseIf sh.Name = "P1" Or sh.Name = "P2" Or sh.Name = "x1" Or sh.Name = "x2" Or sh.Name = "M1" Or sh.Name = "M2" Then
                sh.Delete
            ElseIf sh.Name = "mållinietekst" Or sh.Name = "linielastpil0" Or sh.Name = "linielastpil1" Or sh.Name = "linielastpil2" Then
                sh.Delete
            ElseIf sh.Name = "linielastpil3" Or sh.Name = "linielastpil4" Or sh.Name = "linielastpil5" Or sh.Name = "linielastpil6" Then
                sh.Delete
            ElseIf sh.Name = "linielastpil7" Or sh.Name = "linielastpil8" Or sh.Name = "linielastpil9" Or sh.Name = "linielastpil10" Then
                sh.Delete
            ElseIf sh.Name = "linielastpil11" Or sh.Name = "linielastpil12" Or sh.Name = "linielastpil13" Or sh.Name = "linielastpil14" Then
                sh.Delete
            ElseIf sh.Name = "linielastpil15" Or sh.Name = "linielastpil16" Or sh.Name = "linielastpil17" Or sh.Name = "linielastpil18" Then
                sh.Delete
            ElseIf sh.Name = "linielastpil19" Or sh.Name = "linielastpil20" Or sh.Name = "toplinie" Or sh.Name = "P1Tick" Or sh.Name = "M2tekst" Then
                sh.Delete
            ElseIf sh.Name = "P2Tick" Or sh.Name = "mållinievTicker" Or sh.Name = "målliniehTicker" Or sh.Name = "x1tekst" Or sh.Name = "pdlinieconnect" Then
                sh.Delete
            ElseIf sh.Name = "x2tekst" Or sh.Name = "P1tekst" Or sh.Name = "P2tekst" Or sh.Name = "pdlinie" Or sh.Name = "M1tekst" Then
                sh.Delete
            End If
        Next sh
    End With
    
        mySheet.Shapes.AddLine(RYKIND, RYKNED, RYKIND + BJÆLKELÆNGDE, RYKNED).Select 'her tegnes bjælke
        Selection.ShapeRange.Line.Weight = 6#
        Selection.ShapeRange.Line.Visible = msoTrue
        Selection.ShapeRange.Line.Style = msoLineSingle
        Selection.ShapeRange.Name = "bjælke"
        
        mySheet.Shapes.AddShape(msoShapeIsoscelesTriangle, RYKIND - 7, RYKNED + 5, 16.5, 17.25).Select 'her tegnes venstre understøtning
        Selection.ShapeRange.Line.Weight = 2#
        Selection.ShapeRange.Line.Visible = msoTrue
        Selection.ShapeRange.Line.Style = msoLineSingle
        Selection.ShapeRange.Name = "venstre"
        
        mySheet.Shapes.AddShape(msoShapeIsoscelesTriangle, RYKIND + BJÆLKELÆNGDE - 9, RYKNED + 5, 16.5, 17.25).Select 'her tegnes højre understøtning
        Selection.ShapeRange.Line.Weight = 2#
        Selection.ShapeRange.Line.Visible = msoTrue
        Selection.ShapeRange.Line.Style = msoLineSingle
        Selection.ShapeRange.Name = "højre"
        
        mySheet.Shapes.AddLine(RYKIND, RYKNED + 50, RYKIND + BJÆLKELÆNGDE, RYKNED + 50).Select 'her tegnes mållinie
        Selection.ShapeRange.Line.Weight = 1#
        Selection.ShapeRange.Line.Visible = msoTrue
        Selection.ShapeRange.Line.Style = msoLineSingle
        Selection.ShapeRange.Name = "mållinie"
    .
    .
    .    
    .
    .
    .
    .
    .
    .
    
    
        Range("F18").Select
    End Sub

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Shapes works in one workbook but not another

    Linestyle should be one of the following values.

    msoLineSingle 1
    msoLineThickBetweenThin 5
    msoLineThinThick 3
    msoLineStyleMixed -2
    msoLineThickThin 4
    msoLineThickThin 2

    your code results in either 0 or -1, both of which are invalid and will raise the outside the limits error.
        Selection.ShapeRange.Line.Style = msoLineSingleSelection.ShapeRange.Name = "bjælke"
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    11-26-2009
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2019
    Posts
    46

    Re: Shapes works in one workbook but not another

    Hello Andy.

    That's not the problem.

    The code looks like this: (i accidently copied two line together in the first post)

     mySheet.Shapes.AddLine(RYKIND, RYKNED, RYKIND + BJÆLKELÆNGDE, RYKNED).Select 
        Selection.ShapeRange.Line.Weight = 6#
        Selection.ShapeRange.Line.Visible = msoTrue
        Selection.ShapeRange.Line.Style = msoLineSingle
        Selection.ShapeRange.Name = "bjælke"
    The stand-alone code i wrote works with a part of the code looking like the above

  4. #4
    Registered User
    Join Date
    11-26-2009
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2019
    Posts
    46

    Re: Shapes works in one workbook but not another

    Now i've tryed to have both my main workbook and the drawing workbook open.

    If i call the drawingprocedure (located in the drawing workbook) from my main workbook it works just fine.

    But if i copy the drawing procedure from the drawing workbook to my main workbook and then calls the same procedure (now loacated in main workbook) if fails!

    I'm very confused

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Shapes works in one workbook but not another

    As you point out your code works.

    Can you post an example workbook that produces the error?

  6. #6
    Registered User
    Join Date
    11-26-2009
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2019
    Posts
    46

    Re: Shapes works in one workbook but not another

    Quote Originally Posted by Andy Pope View Post
    As you point out your code works.

    Can you post an example workbook that produces the error?
    I'll post the complete drawingprocedure first (in the next couple of post due to max lenght in one post):

     Sub tegne()
    
    Set mySheet = ActiveSheet
    Dim sh As Shape
    Dim pdlinie As Single, P1 As Single, P2 As Single, x1 As Single, x2 As Single, M1 As Single, M2 As Single
    Dim totallast As Single, pdlinieHøjde As Single, P1Højde As Single, P2Højde As Single, x1Længde As Single
    Dim x2Længde As Single, længde As Single, afstand As Single
    Dim tæller As Byte
    Dim P1tekstplacering As Integer, P2tekstplacering As Integer, flytbidragP1 As Integer, flytbidragP2 As Integer
    Dim P1HøjdeTillæg As Integer, P2HøjdeTillæg As Integer
    
    Const BJÆLKELÆNGDE As Integer = 275
    Const RYKIND As Integer = 75
    Const RYKNED As Integer = 200
    Const MAXLASTHØJDE As Integer = 80
    Const STEPS As Byte = 15 'må højst vælges til 20
    
    afstand = BJÆLKELÆNGDE / STEPS
    
    længde = Range("O46").Value
    pdlinie = Range("O19").Value
    P1 = Range("O25").Value
    P2 = Range("O32").Value
    x1 = Range("O26").Value
    x2 = Range("O33").Value
    M1 = Range("O35").Value
    M2 = Range("O36").Value
    
    If P1 >= P2 Then
        totallast = pdlinie + P1
    Else: totallast = pdlinie + P2
    End If
            
    pdlinieHøjde = pdlinie * MAXLASTHØJDE / totallast
    P1Højde = P1 * MAXLASTHØJDE / totallast
    If P1Højde < 0.2 * MAXLASTHØJDE Then
        P1HøjdeTillæg = 0.2 * MAXLASTHØJDE
        P1Højde = 0.1 * MAXLASTHØJDE
    Else: P1HøjdeTillæg = P1Højde
    End If
    P2Højde = P2 * MAXLASTHØJDE / totallast
    If P2Højde < 0.2 * MAXLASTHØJDE Then
        P2HøjdeTillæg = 0.2 * MAXLASTHØJDE
        P2Højde = 0.1 * MAXLASTHØJDE
    Else: P2HøjdeTillæg = P2Højde
    End If
    
    x1Længde = x1 * BJÆLKELÆNGDE / længde
    x2Længde = x2 * BJÆLKELÆNGDE / længde
    
    With mySheet 'Her renses arket for gamle shapes
       For Each sh In .Shapes
            If sh.Name = "bjælke" Or sh.Name = "venstre" Or sh.Name = "højre" Or sh.Name = "mållinie" Or sh.Name = "pdlinie" Then
                sh.Delete
            ElseIf sh.Name = "P1" Or sh.Name = "P2" Or sh.Name = "x1" Or sh.Name = "x2" Or sh.Name = "M1" Or sh.Name = "M2" Then
                sh.Delete
            ElseIf sh.Name = "mållinietekst" Or sh.Name = "linielastpil0" Or sh.Name = "linielastpil1" Or sh.Name = "linielastpil2" Then
                sh.Delete
            ElseIf sh.Name = "linielastpil3" Or sh.Name = "linielastpil4" Or sh.Name = "linielastpil5" Or sh.Name = "linielastpil6" Then
                sh.Delete
            ElseIf sh.Name = "linielastpil7" Or sh.Name = "linielastpil8" Or sh.Name = "linielastpil9" Or sh.Name = "linielastpil10" Then
                sh.Delete
            ElseIf sh.Name = "linielastpil11" Or sh.Name = "linielastpil12" Or sh.Name = "linielastpil13" Or sh.Name = "linielastpil14" Then
                sh.Delete
            ElseIf sh.Name = "linielastpil15" Or sh.Name = "linielastpil16" Or sh.Name = "linielastpil17" Or sh.Name = "linielastpil18" Then
                sh.Delete
            ElseIf sh.Name = "linielastpil19" Or sh.Name = "linielastpil20" Or sh.Name = "toplinie" Or sh.Name = "P1Tick" Or sh.Name = "M2tekst" Then
                sh.Delete
            ElseIf sh.Name = "P2Tick" Or sh.Name = "mållinievTicker" Or sh.Name = "målliniehTicker" Or sh.Name = "x1tekst" Or sh.Name = "pdlinieconnect" Then
                sh.Delete
            ElseIf sh.Name = "x2tekst" Or sh.Name = "P1tekst" Or sh.Name = "P2tekst" Or sh.Name = "pdlinie" Or sh.Name = "M1tekst" Then
                sh.Delete
            End If
        Next sh
    End With
    
        mySheet.Shapes.AddLine(RYKIND, RYKNED, RYKIND + BJÆLKELÆNGDE, RYKNED).Select 'her tegnes bjælke
        Selection.ShapeRange.Line.Weight = 6#
        Selection.ShapeRange.Line.Visible = msoTrue
        Selection.ShapeRange.Line.Style = msoLineSingle
        Selection.ShapeRange.Name = "bjælke"
        
        mySheet.Shapes.AddShape(msoShapeIsoscelesTriangle, RYKIND - 7, RYKNED + 5, 16.5, 17.25).Select 'her tegnes venstre understøtning
        Selection.ShapeRange.Line.Weight = 2#
        Selection.ShapeRange.Line.Visible = msoTrue
        Selection.ShapeRange.Line.Style = msoLineSingle
        Selection.ShapeRange.Name = "venstre"
        
        mySheet.Shapes.AddShape(msoShapeIsoscelesTriangle, RYKIND + BJÆLKELÆNGDE - 9, RYKNED + 5, 16.5, 17.25).Select 'her tegnes højre understøtning
        Selection.ShapeRange.Line.Weight = 2#
        Selection.ShapeRange.Line.Visible = msoTrue
        Selection.ShapeRange.Line.Style = msoLineSingle
        Selection.ShapeRange.Name = "højre"
        
        mySheet.Shapes.AddLine(RYKIND, RYKNED + 50, RYKIND + BJÆLKELÆNGDE, RYKNED + 50).Select 'her tegnes mållinie
        Selection.ShapeRange.Line.Weight = 1#
        Selection.ShapeRange.Line.Visible = msoTrue
        Selection.ShapeRange.Line.Style = msoLineSingle
        Selection.ShapeRange.Name = "mållinie"
        
        mySheet.Shapes.AddLine(RYKIND, RYKNED + 47, RYKIND, RYKNED + 53).Select 'her tegnes mållinies venstre ticker
        Selection.ShapeRange.Line.Weight = 1#
        Selection.ShapeRange.Line.Visible = msoTrue
        Selection.ShapeRange.Line.Style = msoLineSingle
        Selection.ShapeRange.Name = "mållinievTicker"
        
        mySheet.Shapes.AddLine(RYKIND + BJÆLKELÆNGDE, RYKNED + 47, RYKIND + BJÆLKELÆNGDE, RYKNED + 53).Select 'her tegnes mållinies højre ticker
        Selection.ShapeRange.Line.Weight = 1#
        Selection.ShapeRange.Line.Visible = msoTrue
        Selection.ShapeRange.Line.Style = msoLineSingle
        Selection.ShapeRange.Name = "målliniehTicker"
         
        mySheet.Shapes.AddTextbox(msoTextOrientationHorizontal, RYKIND + (0.5 * BJÆLKELÆNGDE) - 10, RYKNED + 33, 10, 14).Select 'hmållinietekst
        Selection.Characters.Text = "L"
        With Selection.Characters(Start:=1, Length:=1).Font
            .Name = "Arial"
            .FontStyle = "Normal"
            .Size = 10
        End With
        With Selection.ShapeRange
            .Fill.Visible = msoFalse
            .Fill.Transparency = 0#
            .Line.Weight = 0.75
            .Line.DashStyle = msoLineSolid
            .Line.Style = msoLineSingle
            .Line.Transparency = 0#
            .Line.Visible = msoFalse
        End With
        Selection.ShapeRange.Name = "mållinietekst"
        
    If pdlinie > 0 Then
       For tæller = 0 To STEPS
            mySheet.Shapes.AddLine(RYKIND + tæller * afstand, RYKNED - pdlinieHøjde, RYKIND + tæller * afstand, RYKNED - 5).Select 'linielast
            Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadTriangle
            Selection.ShapeRange.Line.EndArrowheadLength = msoArrowheadLengthMedium
            Selection.ShapeRange.Line.EndArrowheadWidth = msoArrowheadWidthMedium
            Selection.ShapeRange.Name = "linielastpil" & tæller
        Next tæller
        
            mySheet.Shapes.AddLine(RYKIND, RYKNED - pdlinieHøjde, RYKIND + BJÆLKELÆNGDE, RYKNED - pdlinieHøjde).Select 'toplinie
            Selection.ShapeRange.Line.Weight = 0.75
            Selection.ShapeRange.Line.Visible = msoTrue
            Selection.ShapeRange.Line.Style = msoLineSingle
            Selection.ShapeRange.Name = "toplinie"
            
            mySheet.Shapes.AddTextbox(msoTextOrientationHorizontal, RYKIND - 68, RYKNED - 0.85 * MAXLASTHØJDE, 35, 15).Select 'pdlinie tekst
            Selection.Characters.Text = "pd,linie"
            With Selection.Characters(Start:=1, Length:=5).Font
                .Name = "Arial"
                .FontStyle = "Normal"
                .Size = 10
            End With
            With Selection.ShapeRange
                .Fill.Visible = msoFalse
                .Fill.Transparency = 0#
                .Line.Weight = 0.75
                .Line.DashStyle = msoLineSolid
                .Line.Style = msoLineSingle
                .Line.Transparency = 0#
                .Line.Visible = msoFalse
            End With
            Selection.ShapeRange.Name = "pdlinie"
            
            mySheet.Shapes.AddLine(RYKIND - 33, RYKNED - 0.85 * MAXLASTHØJDE + 8, RYKIND, RYKNED - pdlinieHøjde).Select 'linie fra pdlinie tekst
            Selection.ShapeRange.Line.Weight = 0.75
            Selection.ShapeRange.Line.Visible = msoTrue
            Selection.ShapeRange.Line.Style = msoLineSingle
            Selection.ShapeRange.Name = "pdlinieconnect"

  7. #7
    Registered User
    Join Date
    11-26-2009
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2019
    Posts
    46

    Re: Shapes works in one workbook but not another

     If M1 > 0 Then
                mySheet.Shapes.AddShape(msoShapeCircularArrow, RYKIND - 23 - M1 * 0.26, RYKNED - M1 * 0.15 - 10, 15 + 0.35 * M1, 15 + 0.35 * M1).Select
                Selection.ShapeRange.Flip msoFlipHorizontal
                Selection.ShapeRange.IncrementRotation -90
                If M1 <= 50 Then
                    Selection.ShapeRange.Fill.ForeColor.SchemeColor = 11
                ElseIf M1 <= 75 Then
                    Selection.ShapeRange.Fill.ForeColor.SchemeColor = 13
                Else:
                    Selection.ShapeRange.Fill.ForeColor.SchemeColor = 10
                End If
                Selection.ShapeRange.Fill.Visible = msoTrue
                Selection.ShapeRange.Fill.Solid
                Selection.ShapeRange.Name = "M1"
                
                mySheet.Shapes.AddTextbox(msoTextOrientationHorizontal, RYKIND - 42 - M1 * 0.26, RYKNED - 10, 20, 15).Select 'M1 tekst
                Selection.Characters.Text = "M1"
                With Selection.Characters(Start:=1, Length:=2).Font
                    .Name = "Arial"
                    .FontStyle = "Normal"
                    .Size = 10
                End With
                With Selection.ShapeRange
                    .Fill.Visible = msoFalse
                    .Fill.Transparency = 0#
                    .Line.Weight = 0.75
                    .Line.DashStyle = msoLineSolid
                    .Line.Style = msoLineSingle
                    .Line.Transparency = 0#
                    .Line.Visible = msoFalse
                End With
                Selection.ShapeRange.Name = "M1tekst"
            End If
        
            If M2 > 0 Then
                mySheet.Shapes.AddShape(msoShapeCircularArrow, RYKIND + BJÆLKELÆNGDE + 10 - M2 * 0.1, RYKNED - M2 * 0.15 - 10, 15 + 0.35 * M2, 15 + 0.35 * M2).Select
                Selection.ShapeRange.IncrementRotation 90
                If M2 <= 50 Then
                    Selection.ShapeRange.Fill.ForeColor.SchemeColor = 11
                ElseIf M2 <= 75 Then
                    Selection.ShapeRange.Fill.ForeColor.SchemeColor = 13
                Else:
                    Selection.ShapeRange.Fill.ForeColor.SchemeColor = 10
                End If
                Selection.ShapeRange.Fill.Visible = msoTrue
                Selection.ShapeRange.Fill.Solid
                Selection.ShapeRange.Name = "M2"
                
                mySheet.Shapes.AddTextbox(msoTextOrientationHorizontal, RYKIND + BJÆLKELÆNGDE + 27 + M2 * 0.25, RYKNED - 10, 20, 15).Select  'M2 tekst
                Selection.Characters.Text = "M2"
                With Selection.Characters(Start:=1, Length:=2).Font
                    .Name = "Arial"
                    .FontStyle = "Normal"
                    .Size = 10
                End With
                With Selection.ShapeRange
                    .Fill.Visible = msoFalse
                    .Fill.Transparency = 0#
                    .Line.Weight = 0.75
                    .Line.DashStyle = msoLineSolid
                    .Line.Style = msoLineSingle
                    .Line.Transparency = 0#
                    .Line.Visible = msoFalse
                End With
                Selection.ShapeRange.Name = "M2tekst"
            End If
    End If
                 
    If P1 > 0 Then 'P1 tegnes hvis den er større end 0
            mySheet.Shapes.AddLine(RYKIND + x1Længde, RYKNED - pdlinieHøjde - 5 - P1Højde, RYKIND + x1Længde, RYKNED - pdlinieHøjde - 5).Select 'P1
            If P1 <= 6 Then
                Selection.ShapeRange.Line.Weight = 0.75
                flytbidragP1 = 18
            ElseIf P1 <= 9 Then
                Selection.ShapeRange.Line.Weight = 1.5
                 flytbidragP1 = 20
            ElseIf P1 <= 12 Then
                Selection.ShapeRange.Line.Weight = 2.5
                 flytbidragP1 = 20
            ElseIf P1 <= 15 Then
                Selection.ShapeRange.Line.Weight = 3.75
                 flytbidragP1 = 21
            ElseIf P1 <= 18 Then
                Selection.ShapeRange.Line.Weight = 5.25
                 flytbidragP1 = 23
            Else:
                Selection.ShapeRange.Line.Weight = 7
                 flytbidragP1 = 23
            End If
            
            Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadTriangle
            Selection.ShapeRange.Line.EndArrowheadLength = msoArrowheadLengthMedium
            Selection.ShapeRange.Line.EndArrowheadWidth = msoArrowheadWidthMedium
            Selection.ShapeRange.Name = "P1"
            
            mySheet.Shapes.AddLine(RYKIND, RYKNED - MAXLASTHØJDE - 10, RYKIND + x1Længde, RYKNED - MAXLASTHØJDE - 10).Select 'x1 linie
            Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadTriangle
            Selection.ShapeRange.Line.EndArrowheadLength = msoArrowheadLengthMedium
            Selection.ShapeRange.Line.EndArrowheadWidth = msoArrowheadWidthMedium
            Selection.ShapeRange.Line.BeginArrowheadStyle = msoArrowheadNone
            Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadOpen
            Selection.ShapeRange.Line.EndArrowheadWidth = msoArrowheadWidthMedium
            Selection.ShapeRange.Line.EndArrowheadLength = msoArrowheadLengthMedium
            Selection.ShapeRange.Line.Visible = msoTrue
            Selection.ShapeRange.Name = "x1"
            
            mySheet.Shapes.AddLine(RYKIND, RYKNED - MAXLASTHØJDE - 7, RYKIND, RYKNED - MAXLASTHØJDE - 13).Select 'P1 venstre ticker
            Selection.ShapeRange.Line.Weight = 0.75
            Selection.ShapeRange.Line.Visible = msoTrue
            Selection.ShapeRange.Line.Style = msoLineSingle
            Selection.ShapeRange.Name = "P1Tick"
            
            mySheet.Shapes.AddTextbox(msoTextOrientationHorizontal, RYKIND - 15, RYKNED - MAXLASTHØJDE - 17, 15, 17).Select 'x1 tekst
            Selection.Characters.Text = "x1"
            With Selection.Characters(Start:=1, Length:=2).Font
                .Name = "Arial"
                .FontStyle = "Normal"
                .Size = 10
            End With
            With Selection.ShapeRange
                .Fill.Visible = msoFalse
                .Fill.Transparency = 0#
                .Line.Weight = 0.75
                .Line.DashStyle = msoLineSolid
                .Line.Style = msoLineSingle
                .Line.Transparency = 0#
                .Line.Visible = msoFalse
            End With
            Selection.ShapeRange.Name = "x1tekst"
            
            If x1 <= x2 Or x2 = 0 Then 'flytter tekst på venstre side hvis x1<=x2 og ellers på højre side
                P1tekstplacering = -flytbidragP1
            ElseIf x1 > x2 Then
                P1tekstplacering = flytbidragP1 - 12
            End If
            
            mySheet.Shapes.AddTextbox(msoTextOrientationHorizontal, RYKIND + x1Længde + P1tekstplacering, RYKNED - pdlinieHøjde - P1HøjdeTillæg, 17, 19).Select 'P1 tekst
            Selection.Characters.Text = "P1"
            With Selection.Characters(Start:=1, Length:=2).Font
                .Name = "Arial"
                .FontStyle = "Normal"
                .Size = 10
            End With
            With Selection.ShapeRange
                .Fill.Visible = msoFalse
                .Fill.Transparency = 0#
                .Line.Weight = 0.75
                .Line.DashStyle = msoLineSolid
                .Line.Style = msoLineSingle
                .Line.Transparency = 0#
                .Line.Visible = msoFalse
            End With
            Selection.ShapeRange.Name = "P1tekst"
    End If
            
    If P2 > 0 Then 'P2 tegnes hvis den er større end 0
            mySheet.Shapes.AddLine(RYKIND + x2Længde, RYKNED - pdlinieHøjde - 5 - P2Højde, RYKIND + x2Længde, RYKNED - pdlinieHøjde - 5).Select 'P2
            If P2 <= 6 Then
                Selection.ShapeRange.Line.Weight = 0.75
                flytbidragP2 = 2
            ElseIf P2 <= 9 Then
                Selection.ShapeRange.Line.Weight = 1.5
                 flytbidragP2 = 3
            ElseIf P2 <= 12 Then
                Selection.ShapeRange.Line.Weight = 2.5
                 flytbidragP2 = 5
            ElseIf P2 <= 15 Then
                Selection.ShapeRange.Line.Weight = 3.75
                 flytbidragP2 = 7.5
            ElseIf P2 <= 18 Then
                Selection.ShapeRange.Line.Weight = 5.25
                 flytbidragP2 = 10.5
            Else:
                Selection.ShapeRange.Line.Weight = 7
                 flytbidragP2 = 8
            End If
            Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadTriangle
            Selection.ShapeRange.Line.EndArrowheadLength = msoArrowheadLengthMedium
            Selection.ShapeRange.Line.EndArrowheadWidth = msoArrowheadWidthMedium
            Selection.ShapeRange.Name = "P2"
        
            mySheet.Shapes.AddLine(RYKIND, RYKNED - MAXLASTHØJDE - 30, RYKIND + x2Længde, RYKNED - MAXLASTHØJDE - 30).Select 'x2 linie
            Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadTriangle
            Selection.ShapeRange.Line.EndArrowheadLength = msoArrowheadLengthMedium
            Selection.ShapeRange.Line.EndArrowheadWidth = msoArrowheadWidthMedium
            Selection.ShapeRange.Line.BeginArrowheadStyle = msoArrowheadNone
            Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadOpen
            Selection.ShapeRange.Line.EndArrowheadWidth = msoArrowheadWidthMedium
            Selection.ShapeRange.Line.EndArrowheadLength = msoArrowheadLengthMedium
            Selection.ShapeRange.Line.Visible = msoTrue
            Selection.ShapeRange.Name = "x2"
            
            mySheet.Shapes.AddLine(RYKIND, RYKNED - MAXLASTHØJDE - 33, RYKIND, RYKNED - MAXLASTHØJDE - 27).Select 'P2 venstre ticker
            Selection.ShapeRange.Line.Weight = 0.75
            Selection.ShapeRange.Line.Visible = msoTrue
            Selection.ShapeRange.Line.Style = msoLineSingle
            Selection.ShapeRange.Name = "P2Tick"

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Shapes works in one workbook but not another

    You need to tell us the values on the sheet that the program uses.
    Also how are you running the routines, from a shortcut or button or macro dialog?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1