Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1744to1748
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

.bmp to Desktop: Frame l/o entfernen

.bmp to Desktop: Frame l/o entfernen
10.03.2020 16:07:45
Dome
Hi zusammen,
Ich erstelle aus Excel (Hintergrund schwarz, ohne Gitternetzlinien) eine Bitmap-Datei, welche als Desktophintergrund fungiert. (nicht full screen, sondern zentriert, der "restliche" Desktophintergrund ist auch schwarz)
Dabei habe ich am linken und oberen Rand eine art "Halo-Effekt", den ich nicht wegbekomme. (sollte auch schwarz sein)
Wie bekomme ich diesen Rand weg?
Vielen Dank für Eure Unterstützung...
LG
Dome

19
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
Schwarz übermalen! ;-) (owT)
10.03.2020 16:18:49
EtoPHG

AW: .bmp to Desktop: Frame l/o entfernen
10.03.2020 17:08:18
onur
Was hat das jetzt mit Excel oder VBA zu tun?
..., weil die .bmp via VBA aus XLSX..
11.03.2020 06:44:55
Dome
...erzeugt wird und ich nicht sicher bin, ob dies im Code überhaupt korrigiert werden kann und nicht ein allgemeines Problem mit Bildern/Bitmap etc. ist.
LG
Dome
..., weil die .bmp via VBA aus XLSX..
11.03.2020 06:44:59
Dome
...erzeugt wird und ich nicht sicher bin, ob dies im Code überhaupt korrigiert werden kann und nicht ein allgemeines Problem mit Bildern/Bitmap etc. ist.
LG
Dome
..., weil die .bmp via VBA aus XLSX..
11.03.2020 06:45:01
Dome
...erzeugt wird und ich nicht sicher bin, ob dies im Code überhaupt korrigiert werden kann und nicht ein allgemeines Problem mit Bildern/Bitmap etc. ist.
LG
Dome
..., weil die .bmp via VBA aus XLSX..
11.03.2020 06:45:06
Dome
...erzeugt wird und ich nicht sicher bin, ob dies im Code überhaupt korrigiert werden kann und nicht ein allgemeines Problem mit Bildern/Bitmap etc. ist.
LG
Dome
Anzeige
AW: ..., weil die .bmp via VBA aus XLSX..
11.03.2020 09:40:27
Nepumuk
Hallo,
zeig doch mal deinen Code.
Gruß
Nepumuk
Code
12.03.2020 08:59:40
Dome
Guten Morgen,

Option Explicit
Option Private Module
Private Declare Function SystemParametersInfoA Lib "user32.dll" ( _
ByVal uAction As Long, _
ByVal uParam As Long, _
ByVal lpvParam As Any, _
ByVal fuWinIni As Long) As Long
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" ( _
ByRef PicDesc As PIC_DESC, _
ByRef RefIID As GUID, _
ByVal fPictureOwnsHandle As Long, _
ByRef IPic As IPictureDisp) As Long
Private Declare Function CopyImage Lib "user32.dll" ( _
ByVal handle As Long, _
ByVal un1 As Long, _
ByVal n1 As Long, _
ByVal n2 As Long, _
ByVal un2 As Long) As Long
Private Declare Function IsClipboardFormatAvailable Lib "user32.dll" ( _
ByVal wFormat As Integer) As Long
Private Declare Function OpenClipboard Lib "user32.dll" ( _
ByVal hWnd As Long) As Long
Private Declare Function GetClipboardData Lib "user32.dll" ( _
ByVal wFormat As Integer) As Long
Private Declare Function DeleteObject Lib "gdi32.dll" ( _
ByVal hObject As Long) As Long
Private Declare Function CLSIDFromString Lib "ole32.dll" ( _
ByVal lpsz As Any, _
ByRef pCLSID As GUID) As Long
Private Declare Function EmptyClipboard Lib "user32.dll" () As Long
Private Declare Function CloseClipboard Lib "user32.dll" () As Long
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Type PIC_DESC
lngSize As Long
lngType As Long
lnghPic As Long
lnghPal As Long
End Type
Private Const PICTYPE_BITMAP As Long = 1
Private Const CF_BITMAP As Long = 2
Private Const IMAGE_BITMAP As Long = 0
Private Const LR_COPYRETURNORG  As Long = &H4
Private Const SPI_SETDESKWALLPAPER As Long = 20
Private Const SPIF_SENDWININICHANGE As Long = &H2
Private Const GUID_IPICTUREDISP As String = "{7BF80981-BF32-101A-8BBB-00AA00300CAB}"
Private llngCopy As Long
Private Function Paste_Picture() As IPictureDisp
Dim lngReturn As Long, lngPointer As Long
If CBool(IsClipboardFormatAvailable(CF_BITMAP)) Then
lngReturn = OpenClipboard(Application.hWnd)
If lngReturn > 0 Then
lngPointer = GetClipboardData(CF_BITMAP)
llngCopy = CopyImage(lngPointer, _
IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG)
Call CloseClipboard
If lngPointer  0 Then Set Paste_Picture = _
Create_Picture(llngCopy, 0&, CF_BITMAP)
End If
End If
End Function
Private Function Create_Picture( _
ByVal lnghPic As Long, _
ByVal lnghPal As Long, _
ByVal lngPicType As Long) As IPictureDisp
Dim udtPicInfo As PIC_DESC, udtID_IDispatch As GUID
Dim objPicture As IPictureDisp
Call CLSIDFromString(StrPtr( _
GUID_IPICTUREDISP), udtID_IDispatch)
With udtPicInfo
.lngSize = Len(udtPicInfo)
.lngType = PICTYPE_BITMAP
.lnghPic = lnghPic
.lnghPal = lnghPal
End With
Call OleCreatePictureIndirect(udtPicInfo, _
udtID_IDispatch, 0&, objPicture)
Set Create_Picture = objPicture
Set objPicture = Nothing
End Function
Public Sub CreateDesktopPicture()
Const FILE_NAME As String = "O:\...\Desktop.bmp"       'Pfad anpassen !!!!!!!!!!!!!!!!
Dim objPicture As IPictureDisp
Call OpenClipboard(Application.hWnd)
Call EmptyClipboard
Call CloseClipboard
Call Tabelle2.Range("A1:L13").CopyPicture _
(Appearance:=xlScreen, Format:=xlBitmap)            'Tabelle und Bereich anpassen !!!!!! _
Set objPicture = Paste_Picture()
If Not objPicture Is Nothing Then
Call SavePicture(Picture:=objPicture, Filename:=FILE_NAME)
Call SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, FILE_NAME, SPIF_SENDWININICHANGE)
Else
MsgBox "Error - table can't show on desktop", vbCritical, "Error"
End If
Call DeleteObject(llngCopy)
End Sub
LG
Dome
Anzeige
AW: Code
12.03.2020 15:08:21
Nepumuk
Hallo,
sieht irgenwie nach meinem Code aus. :-)
dann schneiden wir mal ein Pixel links und oben ab:
Public Sub CreateDesktopPicture()
    
    Dim strFirstFileName As String, strSecondFileName As String
    Dim objPicture As IPictureDisp
    Dim objImageFile As Object
    Dim objImageProcess As Object
    
    Call OpenClipboard(Application.hWnd)
    Call EmptyClipboard
    Call CloseClipboard
    
    Call Tabelle2.Range("A1:L13").CopyPicture _
        (Appearance:=xlScreen, Format:=xlBitmap)
    
    Set objPicture = Paste_Picture()
    
    If Not objPicture Is Nothing Then
        
        strFirstFileName = Environ$("TMP") & "\TMP.bmp"
        
        Call SavePicture(Picture:=objPicture, Filename:=strFirstFileName)
        
        strSecondFileName = Environ$("TMP") & "\Desktop.bmp"
        
        If Dir$(PathName:=strSecondFileName) <> vbNullString Then _
            Call Kill(PathName:=strSecondFileName)
        
        Set objImageFile = CreateObject(Class:="WIA.ImageFile")
        Set objImageProcess = CreateObject(Class:="WIA.ImageProcess")
        
        Call objImageFile.LoadFile(Filename:=strFirstFileName)
        
        Call objImageProcess.Filters.Add(FilterID:=objImageProcess.FilterInfos("Crop").FilterID)
        
        With objImageProcess.Filters(1)
            .Properties("Top") = 1
            .Properties("Bottom") = 0
            .Properties("Left") = 1
            .Properties("Right") = 0
        End With
        
        Set objImageFile = objImageProcess.Apply(Source:=objImageFile)
        
        Call objImageFile.SaveFile(Filename:=strSecondFileName)
        
        Set objImageFile = Nothing
        Set objImageProcess = Nothing
        
        Call SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, strSecondFileName, SPIF_SENDWININICHANGE)
        
        Call Kill(PathName:=strFirstFileName)
        
    Else
        MsgBox "Error - table can't show on desktop", vbCritical, "Error"
    End If
    
    Call DeleteObject(llngCopy)
    
End Sub

Gruß
Nepumuk
Anzeige
AW: Code
13.03.2020 09:19:17
Dome
Hi Nepomuk,
Vielen Dank, das funktioniert perfekt.
Bestünde die Möglichkeit, für mehrere Ranges mehrere Bitmaps zu erzeugen?
Range("B6:N18") wird zu Windows1.bmp
Range("B20:N32") wird zu Windows2.bmp
etc.
LG
Dome
AW: Code
13.03.2020 09:32:22
Nepumuk
Hallo,
ja das geht, aber anzeigen kannst du immer nur eines. Wenn du mehrere anzeigen willst, dann musst du die Ranges in ein neues Tabellenblatt untereinander kopieren und dann aus diesen Ranges ein Gesamtbild machen.
Gruß
Nepumuk
AW: Code
13.03.2020 09:33:20
Nepumuk
Hallo,
ja das geht, aber anzeigen kannst du immer nur eines. Wenn du mehrere anzeigen willst, dann musst du die Ranges in ein neues Tabellenblatt untereinander kopieren und dann aus diesen Ranges ein Gesamtbild machen.
Gruß
Nepumuk
Anzeige
AW: Code
13.03.2020 09:46:45
Dome
Hi Nepomuk,
Ich würde jeweils nur eines anzeigen (bei mir auf dem Desktop). Die restlichen Bitmaps dienen anderen für deren Desktops.
LG
Dominik
AW: Code
13.03.2020 11:38:05
Nepumuk
Hallo,
teste mal:
Public Sub Test()
    Call CreateDesktopPicture("Windows1", Tabelle2.Range("B6:N18"), True)
    Call CreateDesktopPicture("Windows2", Tabelle2.Range("B20:N32"), False)
End Sub

Private Sub CreateDesktopPicture(ByVal pvstrFileName As String, _
        ByRef probjRange As Range, ByVal pvblnShowOnDesktop As Boolean)

    
    Dim strFirstFileName As String, strSecondFileName As String
    Dim objPicture As IPictureDisp
    Dim objImageFile As Object
    Dim objImageProcess As Object
    
    Call OpenClipboard(Application.hWnd)
    Call EmptyClipboard
    Call CloseClipboard
    
    On Error Resume Next
    Do
        DoEvents
        Call probjRange.CopyPicture(Appearance:=xlScreen, Format:=xlBitmap)
        If Err.Number = 0 Then Exit Do
        Call Err.Clear
    Loop
    On Error GoTo 0
    
    Set objPicture = Paste_Picture()
    
    If Not objPicture Is Nothing Then
        
        strFirstFileName = Environ$("TMP") & "\TMP.bmp"
        
        Call SavePicture(Picture:=objPicture, Filename:=strFirstFileName)
        
        strSecondFileName = Environ$("TMP") & "\" & pvstrFileName & ".bmp"
        
        If Dir$(PathName:=strSecondFileName) <> vbNullString Then _
            Call Kill(PathName:=strSecondFileName)
        
        Set objImageFile = CreateObject(Class:="WIA.ImageFile")
        Set objImageProcess = CreateObject(Class:="WIA.ImageProcess")
        
        Call objImageFile.LoadFile(Filename:=strFirstFileName)
        
        Call objImageProcess.Filters.Add(FilterID:=objImageProcess.FilterInfos("Crop").FilterID)
        
        With objImageProcess.Filters(1)
            .Properties("Top") = 1
            .Properties("Bottom") = 0
            .Properties("Left") = 1
            .Properties("Right") = 0
        End With
        
        Set objImageFile = objImageProcess.Apply(Source:=objImageFile)
        
        Call objImageFile.SaveFile(Filename:=strSecondFileName)
        
        Set objImageFile = Nothing
        Set objImageProcess = Nothing
        
        If pvblnShowOnDesktop Then Call SystemParametersInfoA(SPI_SETDESKWALLPAPER, _
            0&, strSecondFileName, SPIF_SENDWININICHANGE)
        
        Call Kill(PathName:=strFirstFileName)
        
    Else
        MsgBox "Error - table can't show on desktop", vbCritical, "Error"
    End If
    
    Call DeleteObject(llngCopy)
    
End Sub

Gruß
Nepumuk
Anzeige
Kein Output erstellt worden
13.03.2020 12:55:53
Dome
Hi Nepomuk,
Wie im Betreff erwähnt ist keine Bitmap abgelegt worden..
LG
Dome
AW: Kein Output erstellt worden
13.03.2020 13:00:56
Nepumuk
Hallo,
schau mal in:
C:\Users\Benutzername\AppData\Local\Temp
Da sind die Dateien.
Gruß
Nepumuk
AW: Kein Output erstellt worden
13.03.2020 13:31:11
Dome
Hi,
Ich habe den Pfad auf meine Bedürfnisse angepasst, aber selbst wenn ich Deinen Code so belasse wird keine .bmp erstellt.
LG
Dome
AW: Kein Output erstellt worden
13.03.2020 13:47:20
Nepumuk
Hallo,
du musst das da ändern:
strSecondFileName = "O:\DeinOrdner\" & pvstrFileName & ".bmp"
Gruß
Nepumuk
AW: Kein Output erstellt worden
16.03.2020 07:27:15
Dome
Guten Morgen Nepomuk,
Ich habe mir das vergangenes Wochenende nochmals zu Gemüte geführt und meinen Fehler gefunden. Unter "DieseArbeitsmappe" hatte ich noch einen zweiten Funktionsaufruf (damals .bmp noch bei Speichern der Arbeitsmappe erstellt worden). Nachdem ich diesen entfernt und die URL angepasst habe, läuft der Code (Dein Code) nun optimal.
Ich danke Dir herzlich für Deine Unterstützung.
#staysafe #covid
LG
Dome
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige