Dieses Forum nutzt Cookies
Dieses Forum verwendet Cookies, um deine Login-Informationen zu speichern, wenn du registriert bist, und deinen letzten Besuch, wenn du es nicht bist. Cookies sind kleine Textdokumente, die auf deinem Computer gespeichert werden. Die von diesem Forum gesetzten Cookies werden nur auf dieser Website verwendet und stellen kein Sicherheitsrisiko dar. Cookies aus diesem Forum speichern auch die spezifischen Themen, die du gelesen hast und wann du zum letzten Mal gelesen hast. Bitte bestätige, ob du diese Cookies akzeptierst oder ablehnst.

Ein Cookie wird in deinem Browser unabhängig von der Wahl gespeichert, um zu verhindern, dass dir diese Frage erneut gestellt wird. Du kannst deine Cookie-Einstellungen jederzeit über den Link in der Fußzeile ändern.

Bild mit korrektem Bildseitenverhältnis in Kommentar einfügen
#1
Hallo,

im englischsprachigen Raum habe ich folgende Funktion gefunden:

Code:
Public Function ImageInComment(ImageFile As Variant, _
    Optional Target As Range = Nothing, _
    Optional ScaleFactor As Single = 1#, _
    Optional RotateAngle As Integer = 0, _
    Optional NoAuthor As Boolean = False) As String

    Dim sResult As String, sFile As String, sPath As String, sPS As String, rCell As Range, bError As Boolean
    Dim oWIA As Object, oIP As Object
   
    Const PtPerInch As Integer = 72 ' points/inch; WIA metrics are pixels and pixels/inch
   
    sResult = "See image in comment, "
    If TypeName(ImageFile) = "Range" Then sFile = ImageFile.Cells(1).Value Else sFile = ImageFile
    sPath = sFile
    sPS = Application.PathSeparator
    If Target Is Nothing Then
        Set rCell = Application.Caller
        sResult = sResult & "this cell"
    Else
        Set rCell = Target.Cells(1)
        sResult = sResult & "cell " & rCell.Address(False, False)
    End If
    bError = (Dir(sPath) = vbNullString Or sFile = vbNullString)
    If bError And sFile <> vbNullString Then
        If ActiveWorkbook.Path <> vbNullString Then
            sPath = ActiveWorkbook.Path & sPS & sFile
            bError = (Dir(sPath) = vbNullString)
        End If
        If bError Then
            sPath = Application.DefaultFilePath & sPS & sFile
            bError = (Dir(sPath) = vbNullString)
        End If
    End If
    Set oWIA = CreateObject("WIA.ImageFile")
    If Not bError Then bError = oWIA.LoadFile(sPath)
    With rCell
        If .Comment Is Nothing Then .AddComment IIf(NoAuthor, " ", vbNullString)
        With .Comment.Shape
            If bError Then
                .Fill.Solid
                sResult = "Invalid ImageFile"
            Else
                Set oIP = Nothing
                Select Case RotateAngle
                Case 90, 180, 270
                    Set oIP = CreateObject("WIA.ImageProcess")
                    oIP.Filters.Add oIP.FilterInfos("RotateFlip").FilterID
                    oIP.Filters(1).Properties("RotationAngle") = RotateAngle
                    Set oWIA = oIP.Apply(oWIA)
                    sFile = sPath
                    sPath = Environ("TEMP") & sPS & GUID_String() & "." & oWIA.FileExtension
                    bError = oWIA.SaveFile(sPath)
                    If bError Then ' restore origiinal image
                        sPath = sFile
                        bError = oWIA.LoadFile(sPath)
                        Set oIP = Nothing
                    End If
                End Select
                .LockAspectRatio = False
                .Height = oWIA.Height * PtPerInch / oWIA.VerticalResolution
                .Width = oWIA.Width * PtPerInch / oWIA.HorizontalResolution
                .LockAspectRatio = True
                .Height = IIf(ScaleFactor > 100, ScaleFactor, .Height * ScaleFactor)
                .Fill.UserPicture sPath
                If Not (oIP Is Nothing) Then
                    Kill sPath
                    Set oIP = Nothing
                End If
            End If
        End With
    End With
    Set oWIA = Nothing
    ImageInComment = sResult
   
End Function
Antworten Top
#2
Hola,

und jetzt?
Gruß,
steve1da
[-] Folgende(r) 1 Nutzer sagt Danke an steve1da für diesen Beitrag:
  • TxbyFmjy
Antworten Top
#3
Entschuldigung



Bild zum Ausprobieren:    


Datei zum Üben:
.xlsx   Function ImageInComment.xlsx (Größe: 9,82 KB / Downloads: 3)
Antworten Top
#4
Hallo,

also ich habe ja eher den Eindruck, dass Du den Code gar nicht vollständig ausprobiert hast. Sonst hättest Du z.B. GUID_String() bemerkt.
Und um ein Bild in einen Kommentar einzufügen, von mir aus auch gedreht, da gibt's ja nun einiges an Code hier und dort.
Na denn, wie auch immer.

Gruß
Microsoft Excel Expert · Microsoft Most Valuable Professional (MVP) :: 2011-2019 & 2020-2022 :: 10 Awards
https://de.excel-translator.de/translator :: Online Excel-Formel-Übersetzer :: Funktionen :: Fehlerwerte :: Argumente :: Tabellenbezeichner
[-] Folgende(r) 1 Nutzer sagt Danke an maninweb für diesen Beitrag:
  • TxbyFmjy
Antworten Top


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste