+ Reply to Thread
Results 1 to 12 of 12

Rebuilding Header in VBA with an Embedded Image

  1. #1
    Registered User
    Join Date
    10-20-2011
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    12

    Rebuilding Header in VBA with an Embedded Image

    I have a Header with an Embedded Image in it. I use the image like a letterhead or watermark when the file is printed. It doesn't seem to be possible to protect the header from being changed by the user via worksheet protections and the workaround seems to be to rebuild the header with VBA, like so:

    Please Login or Register  to view this content.
    (Thanks to Ekim: http://www.mrexcel.com/forum/excel-q...es-header.html)

    I wonder if it is possible to change .Filename = "C:\Temp\logo.jpg" to point to an embedded image hidden on a different, protected sheet, or something similar? Users won't have the image as a local file on their computer so I'm wondering if I can pack it up with the excel document somehow.

    Thank you for your help!

  2. #2
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Rebuilding Header in VBA with an Embedded Image

    You must save image to disk before putting it in header. If image is in ActiveX Image control this is simple with SavePicture function.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  3. #3
    Registered User
    Join Date
    10-20-2011
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Rebuilding Header in VBA with an Embedded Image

    That sounds like it would work. It's getting late tonight but I'll give it a try tomorrow and let you know how it goes.

    Thank you for the advice

  4. #4
    Registered User
    Join Date
    10-20-2011
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Rebuilding Header in VBA with an Embedded Image

    Thanks again for the advice, Izandol. I've been working on saving the image to disk and thought I would report what I've found for anyone else who might be interested.

    1) The image needs to be stored inside a chart (as in, a scatterplot). The chart can be blank except for the image but you need the chart
    2) Make the chart HUGE. At least twice the height and width of the original picture, and expand the picture to fill the chart. Otherwise you're going to lose a lot of resolution in the export.
    3) You have to select the chart either manually or with vba, you can't just export it; it has to receive focus (thus taking it away from whatever the user was doing).

    Anyway, here's the code I got working. This will save the image as a .gif file in the same directory that the workbook is in and will try not to overwrite any existing files. The chart is in "Sheet1" and is the only chart in Sheet1.

    Please Login or Register  to view this content.
    (Based on Don's replay here: http://www.excelforum.com/excel-gene...icture-fi.html)

    Feel free to disagree with anything I've said above

    Cheers.

    -----------------------------------------------------------------------------------------------------------------
    EDIT: I think I need to work on my reading comprehension. I didn't even notice your mention of ActiveX Image Controls, Izandol. I'll give that a try tomorrow. I'll leave the post above alone. It might still be helpful to someone.
    Last edited by microcontrolled; 01-21-2014 at 04:58 AM.

  5. #5
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Rebuilding Header in VBA with an Embedded Image

    You may simply store inside an ActiveX Image control. Then you may use:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-20-2011
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Rebuilding Header in VBA with an Embedded Image

    Quote Originally Posted by Izandol View Post
    You may simply store inside an ActiveX Image control. Then you may use:
    Please Login or Register  to view this content.
    I gave the ActiveX control a shot. It seems to take my jpeg file and convert it into a bmp. This is causing the filesize of the workbook to balloon and performance takes a big hit. Is it possible to keep the file as a jpeg?

  7. #7
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Rebuilding Header in VBA with an Embedded Image

    I do not think it possible to change how the control stores the image. How big is the jpg file?

    It may be simplest to use the chart after all.

  8. #8
    Registered User
    Join Date
    10-20-2011
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Rebuilding Header in VBA with an Embedded Image

    The jpeg is 376 kb but it contains a lot of white space. When uncompressed as a bmp my workbook increases in filesize by about 4 mb.

    Using the chart has a few drawbacks. The picture loses some quality and I have to be careful about moving the focus of the workbook to the chart when saving but it does work well enough.

    Thanks again for your help

  9. #9
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Rebuilding Header in VBA with an Embedded Image

    That seems a large file for a header image?

    You may also wish to experiment with the PastePicture code from Stephen Bullen which can create picture object from the clipboard data.

  10. #10
    Registered User
    Join Date
    10-20-2011
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Rebuilding Header in VBA with an Embedded Image

    The image is large because it covers the whole page. It's the background image we use for letterhead and my charts are printed on top of it. That's also why it has a lot of white space and why it becomes enormous as a BMP

    I downloaded Stephen's code but to be honest it seems a bit over my head . I'm not really sure how it would help me either. If ActiveSheet.PageSetup.LeftHeaderPicture.Filename only accepts a string with a path to a file on the hard drive, how will moving picture object through the clipboard help?

  11. #11
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Rebuilding Header in VBA with an Embedded Image

    The code returns a Picture object, so you may save to file using:
    Please Login or Register  to view this content.
    for example, and then you may load this into the header picture.

  12. #12
    Registered User
    Join Date
    10-20-2011
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Rebuilding Header in VBA with an Embedded Image

    I gave Stephen's code a try with your call. It does take an embedded image object and save it to disk but only as bmp or metafile (which I think is just a wrapper for bmp?). This again creates a giant file. The large bmp it creates isn't even very good looking. I was able to get better image quality by exporting the chart like I did in post #4

    As a side note, I've found that when I export the chart, another interesting property is that the quality of the resulting exported image depends on what zoom setting the chart is on at the time. If the chart is zoomed far out I get a small blurry image, but if it's zoomed in I get a large clear image.

    The chart method is a bit silly but I think it works for me.

+ 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. [SOLVED] VBA to send embedded image in email body- NOT USING THE ORGINAL IMAGE SOURCE
    By Coreyusa in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-27-2013, 06:48 PM
  2. Outlook Embedded Image - Red x
    By VillaLion in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-16-2013, 07:02 AM
  3. Delete image files embedded in excel
    By vemix in forum Excel General
    Replies: 2
    Last Post: 10-17-2012, 02:20 PM
  4. Embedded image
    By jclayland in forum Excel General
    Replies: 2
    Last Post: 04-17-2008, 07:28 AM
  5. How to produce(move) an embedded image using a formula?
    By rbs in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-26-2005, 10:05 AM

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