+ Reply to Thread
Results 1 to 12 of 12

EXCEL, VBA, Image: Image loses transparency after saving woorkbook

  1. #1
    Registered User
    Join Date
    04-12-2011
    Location
    San Jose, California
    MS-Off Ver
    Excel 2003
    Posts
    17

    EXCEL, VBA, Image: Image loses transparency after saving woorkbook

    APPLICATION AND SYSTEM: Excel 2007, WINDOWS 10

    PROBLEM: Imported images with transparent backgrounds appear as expected until the workbook is saved, closed and then re-opened. Upon re-opening, the image appears but without the original transparent background.

    QUESTION: How is the transparent background of an imported gif preserved when the workbook is saved and closed.

    BACKGROUND: I have a workbook which uses the LoadPicture(Application.GetOpenFilename) function to allow the User to populate a Image field with a picture. In our case we will be limiting the selected file(s) as gif format and recommending only those with transparent backgrounds. We then use Worksheets("{SHEET NAME}").Activate: ActiveSheet.OLEObjects("{TARGET IMAGE CONTROL}").Object.Picture = {CURRENT PAGE IMG}.Picture to 'copy' the selected image to image controls on several other sheets in the work book.

    Selecting images and populating image controls now work well: The selected images with transparent backgrounds appear as expected - transparent. However, when re-opening the saved workbook selected images appear without their original transparent backgrounds.

    Any help resolving this would be very much appreciated.

    Regards,
    Last edited by lhasha; 06-17-2016 at 04:03 PM.

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: EXCEL, VBA, Image: Image loses transparency after saving woorkbook

    Hello lhasha,

    ...However, when re-opening the saved workbook selected images appear without their original transparent backgrounds.
    Add the same Code you use for,
    Selecting images and populating image controls now work well: The selected images with transparent backgrounds appear as expected - transparent.
    in the ThisWorkbook Open event, referring to the correct Sheet/s, and or images.

    If you have a problem with that then please attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window (or use the paperclip icon).

    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Registered User
    Join Date
    04-12-2011
    Location
    San Jose, California
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: EXCEL, VBA, Image: Image loses transparency after saving woorkbook

    Winon:

    Are you suggesting that I use code to reload the image when the workbook is again opened? If so, this is not consistent with our need for the the image with the transparent background to persist and travel with worksheet independent of the original image file.

    For years I have retained images in my Excel and Word files without issue. However, the difference is that in those instances I used the menu function 'Import>Picture' and was not using LoadPicture to populate an Image control.
    Sadly, I cannot use a Picture control in the same way as I do the Image control.

    So, please make clear your suggestion to
    Add the same Code you use for, "Selecting images and populating image controls now work well: The selected images with transparent backgrounds appear as expected - transparent."
    in the ThisWorkbook Open event, referring to the correct Sheet/s, and or images.
    Regards

  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: EXCEL, VBA, Image: Image loses transparency after saving woorkbook

    Hi lhasha,

    For years I have retained images in my Excel and Word files without issue. However, the difference is that in those instances I used the menu function 'Import>Picture' and was not using LoadPicture to populate an Image control.
    So, if I understand you correctly you did it manually for years without VBA?

    If my assumption is correct, then Please provide us with a sample Workbook as requested in my Post #2.

    Without a sample Workbook, I don't think anyone would be able to provide you with a ready solution.

    Regards.

  5. #5
    Registered User
    Join Date
    04-12-2011
    Location
    San Jose, California
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: EXCEL, VBA, Image: Image loses transparency after saving woorkbook

    Winon:

    Again, thank you. I have never attempted this before. When I explained what I had done in the past, I was merely explaining that in some
    documents or forms where I might need one or two signatures and they are my own, I would merely use the menu function Import>Picture
    which would result in a Picture container but not an Image control. Whenever I used the menu function Import>Picture approach, and when
    I would save/close and later reopen, the transparent images are fine. Such is not the case doing it as explained herein.

    Here are two (2) screen shots.

    The first is just after the signature image is loaded by double clicking the Image control:


    FirstAdded.jpg

    The second is after the file has been saved and reopened:

    AfterReOpen.jpg
    Last edited by lhasha; 06-18-2016 at 01:11 AM.

  6. #6
    Registered User
    Join Date
    04-12-2011
    Location
    San Jose, California
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: EXCEL, VBA, Image: Image loses transparency after saving woorkbook

    The image loaded as shown in the last post is used to populate several other image fields throughout the workbook.
    This next image shows one of those instances before the save/close:


    SigUsedBeforeSave.jpg

    Next is the same instance after the save/close and when reopened:

    SigUsedAfterReOpen.jpg

    Thank you for exploring this issue further.

    Regards
    Last edited by lhasha; 06-18-2016 at 12:59 AM.

  7. #7
    Registered User
    Join Date
    04-12-2011
    Location
    San Jose, California
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: EXCEL, VBA, Image: Image loses transparency after saving woorkbook

    Here is the code that 1) loads the signature file into the master Image control (getSig) and then populates the five instances of
    the signature (imgSIG) across the various worksheets.

    Private Sub getSig_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    Application.ScreenUpdating = False
    On Error GoTo ErrHandler
    newSig.Picture = LoadPicture(Application.GetOpenFilename) 'ALLOWS USER TO BROWSE AND SELECT IMAGE FILE
    Call UnprotectAll 'SIMPLE UNPROTECT TO ALLOW FOR EDITS
    'NEXT FOR LINES OF CODE POPULATE THE SIGNATURES ACCROSS THE WORKBOOK
    Worksheets("G702").Activate: ActiveSheet.OLEObjects("imgSIG").Object.Picture = newSig.Picture
    Worksheets("CWRPP").Activate: ActiveSheet.OLEObjects("imgSIG").Object.Picture = newSig.Picture
    Worksheets("CWRFP").Activate: ActiveSheet.OLEObjects("imgSIG").Object.Picture = newSig.Picture
    Worksheets("UWRPP").Activate: ActiveSheet.OLEObjects("imgSIG").Object.Picture = newSig.Picture
    Worksheets("UWRFP").Activate: ActiveSheet.OLEObjects("imgSIG").Object.Picture = newSig.Picture
    ErrHandler:
    'RETURNS FOCUS TO THE DASHBOARD TO FIRST EDITABLE CELL
    Sheets("DASHBOARD").Select
    ActiveSheet.Range("C8").Select
    Call ProtectAll 'SIMPLE RE-PROTECT TO DISALLOW EDITS
    Application.ScreenUpdating = True
    End Sub


    I think this is the relative information in total. I again look forward to receiving any advise regarding this issue.

    Regards
    Last edited by lhasha; 06-18-2016 at 01:28 AM.

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: EXCEL, VBA, Image: Image loses transparency after saving woorkbook

    I couldn't replicate the problem.

    Perhaps you could explicitly set the backgrounds transparent?

    Please Login or Register  to view this content.
    Or if necessary, do it each time the workbook opens? This code goes in the ThisWorkbook code module.
    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  9. #9
    Registered User
    Join Date
    04-12-2011
    Location
    San Jose, California
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: EXCEL, VBA, Image: Image loses transparency after saving woorkbook

    AlphaFrog:

    Thank you but when I tried nothing different. It seems your suggested code just sets the controls' background to transparent. This is not the issue. What is happening is the images (originally transparent gifs) lose their transparency and the backgrounds become white.

    Regards,

  10. #10
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: EXCEL, VBA, Image: Image loses transparency after saving woorkbook

    Yeah, it was shot in the dark.

    Have you tested GIFs from other sources to see if maybe it's some sort subtle GIF image format issue from your current source.

    Do you have any code that runs automatically when the file opens? If yes, what is it doing, and can you run a test without it.

  11. #11
    Registered User
    Join Date
    04-12-2011
    Location
    San Jose, California
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: EXCEL, VBA, Image: Image loses transparency after saving woorkbook

    AlphaFrog:

    Nothing I did try gif files from three different sources.

    Just very strange and I cannot believe I am the only one who has encountered this.

    Regards,

  12. #12
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: EXCEL, VBA, Image: Image loses transparency after saving woorkbook

    When posting code, please paste between code tags. Insert tags by clicking the # icon on the toolbar.

    Maybe if you posted some links with transparent background or better yet, attach an obfuscated file as requested earlier would help us help better.

    Excel 2010 and 2016 has a nice feature where the Format ribbon has a button to remove background. That would not help as there are not VBA commands to use it. It does make handling non-transparent backgrounds easy.

    I got some sample sigs that need the background set transparent at: http://www.transpacificagency.com/wp...ncock-logo.gif

    Since I use Excel 2016 on Win10, I am not sure how much my testing would help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Insert Image with transparency
    By Slurry Pumper in forum Excel General
    Replies: 5
    Last Post: 01-19-2016, 03:50 PM
  2. VBA Script for saving an image from Excel to PNG file thru MS Paint
    By alexgempesaw in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-21-2015, 08:09 PM
  3. [SOLVED] How to apply Image borders to an image that my excel vba userform pastes in a word doc?
    By CaptainCool in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-11-2014, 05:40 PM
  4. Excel 2010 "vlookup pictures vba" links image instead of saving it as an image
    By neverdom in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-28-2013, 04:17 AM
  5. Image with transparency on other picture in Userform
    By vanMourik in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-26-2013, 11:57 AM
  6. VBA: Put text from excel to jpeg image by matching image name.
    By sroysroy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-12-2013, 01:47 AM
  7. excel 2010 VBA InsertPicInRange only makes shortcut to image instead of copy of image
    By ArjanSpit in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-10-2012, 02:57 PM

Tags for this Thread

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