Oggetti SHAPE



  • Oggetti SHAPE
    di Hellboy (utente non iscritto) data: 22/11/2015 14:29:47

    Ciao ragazzi, da quando me lo avete suggerito, mi si è aperto un mondo :) :)

    Ora sto lavorando con le forme su un foglio excel, ho necessita di scrivere due quadratini con all'interno un testo.
    Ho organizzato un Modulo con all'interno una SUB, dove passo i 4 valori di X e Y per disegnare un rettangolo, ed il testo.

    Ma quando eseguo il codice, inserito nell'INITIALIZE del form principale, mi da l'errore:
    LIMITI ESAURITI PER l'INDICE DELLA COLLEZIONA SPECIFICATA.

    Cos'è ?
    Come risolvo ?
     
    Public Sub OggettoShape(x1 As Double, y1 As Double, x2 As Double, y2 As Double, testo As String)
    
    
        ActiveSheet.Shapes.AddShape(msoShapeRectangle, X1,Y1,X2,Y2).Select
        Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = testo
        With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 6). _
            ParagraphFormat
            .FirstLineIndent = 0
            .Alignment = msoAlignLeft
        End With
        With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 6).Font
            .NameComplexScript = "+mn-cs"
            .NameFarEast = "+mn-ea"
            .Fill.Visible = msoTrue
            .Fill.ForeColor.ObjectThemeColor = msoThemeColorLight1
            .Fill.ForeColor.TintAndShade = 0
            .Fill.ForeColor.Brightness = 0
            .Fill.Transparency = 0
            .Fill.Solid
            .Size = 11
            .Name = "+mn-lt"
        End With
        Range("A1").Select
    End Sub
    



  • di hellboy (utente non iscritto) data: 22/11/2015 14:32:20

    Scusate, l'evento non si trova nell'INITIALIZE del form, ma nel CLICK di quando premo un CommandButton.



  • di cromagno data: 22/11/2015 16:14:38

    Ciao Hellboy,
    hai dichiarato le variabili ma non gli hai assegnato alcun valore....

    Prova così:
     
    Public Sub OggettoShape()
    Dim x1 As Double, y1 As Double, x2 As Double, y2 As Double, testo As String
    x1 = 50
    x2 = 50
    y1 = 100
    y2 = 100
    testo = "Prova scrittura"
        ActiveSheet.Shapes.AddShape(msoShapeRectangle, x1, y1, x2, y2).Select
        Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = testo
        With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 6). _
            ParagraphFormat
            .FirstLineIndent = 0
            .Alignment = msoAlignLeft
        End With
        With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 6).Font
            .NameComplexScript = "+mn-cs"
            .NameFarEast = "+mn-ea"
            .Fill.Visible = msoTrue
            .Fill.ForeColor.ObjectThemeColor = msoThemeColorLight1
            .Fill.ForeColor.TintAndShade = 0
            .Fill.ForeColor.Brightness = 0
            .Fill.Transparency = 0
            .Fill.Solid
            .Size = 11
            .Name = "+mn-lt"
        End With
        Range("A1").Select
    End Sub



  • di Hellboy (utente non iscritto) data: 22/11/2015 17:16:22

    Si, cosi funziona .... ma io i valori X,Y e testo li devo passare da fuori .... se li inserisco non funziona più.
    Mi da quell'errore.
    Come mai ?

     
    Public Sub OggettoShape(x1 As Double, y1 As Double, x2 As Double, y2 As Double, testo As String)



  • di Albatros54 data: 22/11/2015 17:43:15

    Ho creato una userforms ho inserito un pulsante è incollato il codice sotto all'evento Clik.
    ho modificato alcune righe di codice prova.
    I valori li puoi inserire prelevandoli da una inputbox.
    Ciao
    albatros54  
     
    Private Sub CommandButton1_Click()
    a = InputBox("dammi il valore")
    b = InputBox("dammi il valore")
    c = InputBox("dammi il valore")
    d = InputBox("dammi il valore")
    f = InputBox("dammi il valore")
    Call OggettoShape(a, b, c, d, f)
    End Sub
    
    
    
    In un modulo:
    
    Public Sub OggettoShape(ByVal x1 As Double, ByVal y1 As Double, ByVal x2 As Double, ByVal y2 As Double, ByVal testo As String)
    
    
        ActiveSheet.Shapes.AddShape(msoShapeRectangle, x1, y1, x2, y2).Select
        Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = testo
        With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 6). _
            ParagraphFormat
            .FirstLineIndent = 0
            .Alignment = msoAlignLeft
        End With
        With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 6).Font
            .NameComplexScript = "+mn-cs"
            .NameFarEast = "+mn-ea"
            .Fill.Visible = msoTrue
            .Fill.ForeColor.ObjectThemeColor = msoThemeColorLight1
            .Fill.ForeColor.TintAndShade = 0
            '.Fill.ForeColor.Brightness = 0<<<===Commentato
            .Fill.Transparency = 0
            .Fill.Solid
            .Size = 11
            .Name = "+mn-lt"
        End With
        Range("A1").Select
    End Sub
    






  • di cromagno data: 22/11/2015 18:00:34

    Ciao a tutti,
    Grande Albatros
    @Hellboy credo che la soluzione di Albatros sia quello che ti serviva...



  • di hellboy (utente non iscritto) data: 22/11/2015 18:10:36

    Mi continua a dare quell'errore su questa linea :
    With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 6).ParagraphFormat

    che cavolo di errore e'?



  • di Albatros54 data: 22/11/2015 18:15:33

    prova a sostituire il 6 con il 2, forse funziona






  • di Hellboy (utente non iscritto) data: 23/11/2015 08:36:11

    Niente,continua a darmi errore.
    Questa volta ho provato su un PC con Excel 2007
    e l'errore è cambiato.

    Ora mi dice:
    Proprietà o metodo non supportati dall'oggetto


    Come risolvo ?!?!?!



  • di Hellboy (utente non iscritto) data: 23/11/2015 08:41:16

    RAGAZZI ho risolto, rifacendo l'oggetto shape sull'excel 2007, che è leggermente diverso dal 2016.
    Come mai ?
    C'è la possibilità che ora che lo riporto sul 2016 non funzioni ?

    Questo oggetto cambia a seconda delle versioni ?

    Mmmmmmmmmmmmmmmmmmmh
     
    Public Sub OggettoShape(ByVal x1 As Double, ByVal y1 As Double, ByVal x2 As Double, ByVal y2 As Double, ByVal testo As String)
        ActiveSheet.Shapes.AddShape(msoShapeRectangle, x1, y1, x2, y2).Select
        Selection.Characters.Text = testo
        With Selection.Characters(Start:=1, Length:=4).Font
            .Name = "Arial"
            .FontStyle = "Normale"
            .Size = 10
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("P13").Select
    End Sub