+ Reply to Thread
Results 1 to 16 of 16

Macro to change the background image and copy the image filename into a cell

  1. #1
    Registered User
    Join Date
    09-12-2008
    Location
    Riversul
    MS-Off Ver
    2016
    Posts
    83

    Macro to change the background image and copy the image filename into a cell

    Hello! I believe that the title pretty much covers what I'm intending to do, but I'll try to be more speciifc:

    Is there any way where I can use VBA to change the active sheet's background, and by selecting any random file, to have its filename copied to a specific range (for instance, the filename would be "2000.png", so it'd copy "2000" to A1)? Thanks in advance

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,932

    Re: Macro to change the background image and copy the image filename into a cell

    Quote Originally Posted by Zenarte View Post
    by selecting any random file
    You mean the user selects a file, or the VBA selects a file at random?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    09-12-2008
    Location
    Riversul
    MS-Off Ver
    2016
    Posts
    83

    Re: Macro to change the background image and copy the image filename into a cell

    Thank you for the reply, 6StringJazzer! In that case, the user would select the desired file

  4. #4
    Registered User
    Join Date
    09-12-2008
    Location
    Riversul
    MS-Off Ver
    2016
    Posts
    83

    Re: Macro to change the background image and copy the image filename into a cell

    Hello again, I'm still looking for ways to do achieve that and I still haven't found out if it's possible or not.. Is it really impossible? Thanks

  5. #5
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,693

    Re: Macro to change the background image and copy the image filename into a cell

    Re: "ActiveSheet Background"
    What do you mean by that?
    In the code, it sets the picture size to 10 columns wide and 45 rows height. Change as required.
    You want the picture name in A1 but that would be obscured by the picture so it puts its name in Range("L1") = Cells(1, 12)
    Change references as and where required.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-12-2008
    Location
    Riversul
    MS-Off Ver
    2016
    Posts
    83

    Re: Macro to change the background image and copy the image filename into a cell

    *unnecessary example removed*
    Last edited by Zenarte; 03-27-2022 at 03:42 AM.

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Macro to change the background image and copy the image filename into a cell

    @Zenarte
    Now, one question that could come up is: why would I want to work with a picture set in the background, instead of just normally adding it to the sheet? The thing is that each one of these pictures that I have to work with are like grids. So I've configured the Excel for each one of the cells to overlap the image, just so I could easily identify the reference number for each individual square. I'll add a sheet as an example!
    YOU asked for a picture to be set as background and you example file is not telling use much, even the macro says noting.
    I thing you should take your time and rephrase your question, then read it yourself and think if someone that has no idea what you're trying to do would understand it too.
    Last edited by Keebellah; 03-27-2022 at 03:27 AM.
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  8. #8
    Registered User
    Join Date
    09-12-2008
    Location
    Riversul
    MS-Off Ver
    2016
    Posts
    83

    Re: Macro to change the background image and copy the image filename into a cell

    Keebellah, whenever you set a picture in the background, it utilizes the function "ActiveSheet.SetBackgroundPicture", right? All I wanted to know was to see if is it possible that whenever I click a button, or whatever, I can trigger this macro that will ask me to select a picture and set it in the background. And after I choose the file, the filename will be copied to the A1 cell. That's pretty much it

    Everything else is covered, I just uploaded this example to give you an idea about what I'm working with, but it's really unnecessary. If you can help me clarifying that doubt, I'd be really grateful, thank you

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Macro to change the background image and copy the image filename into a cell

    Does this mean that you want an image you select to be set as background and the name of that file in cell A1?
    Only the filename or also the path of that selected file?
    But setting the mimage as background will not only set it the the area you colured balck it will be the entire sheet and probably tiled if its small

  10. #10
    Registered User
    Join Date
    09-12-2008
    Location
    Riversul
    MS-Off Ver
    2016
    Posts
    83

    Re: Macro to change the background image and copy the image filename into a cell

    Keebellah, thank you for your reply. Yes, if I choose the file "2000.png" as an image in the background, for instance, then it'd be cool if the "2000" value would be automatically written on the A1 cell. Only the filename would be necessary

    I really appreciate your concern and ways that could improve the work, it's just that I couldn't think of an easier way to detect anomalies on those image files, so I've came up with this solution
    Last edited by Zenarte; 03-27-2022 at 04:01 AM.

  11. #11
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Macro to change the background image and copy the image filename into a cell

    Okay, clear, I'll work on an idea and post it when it's ready.
    Bom d燰

  12. #12
    Registered User
    Join Date
    09-12-2008
    Location
    Riversul
    MS-Off Ver
    2016
    Posts
    83

    Re: Macro to change the background image and copy the image filename into a cell

    Keebellah, I really appreciate your patience and attention. Thank you and goedemorgen

  13. #13
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Macro to change the background image and copy the image filename into a cell

    Place this code in one of the empty modules you already have there
    Please Login or Register  to view this content.
    You can then add a button to your sheet and link the macro to this button (Insert_Picture)

  14. #14
    Registered User
    Join Date
    09-12-2008
    Location
    Riversul
    MS-Off Ver
    2016
    Posts
    83

    Re: Macro to change the background image and copy the image filename into a cell

    Wow, this is perfectly working and will definitely help me save a lot of time, thank you very very much, Keebellah and jolivanes!

  15. #15
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Macro to change the background image and copy the image filename into a cell

    Muito prazer,
    Happy coding😀

  16. #16
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,693

    Re: Macro to change the background image and copy the image filename into a cell

    Thanks for letting us know that all is well en een prettige dag verder allebei.

+ 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] Replacing an Image Filename with the Actual Image
    By daniel21805 in forum Word Formatting & General
    Replies: 2
    Last Post: 03-12-2021, 05:43 PM
  2. Insert Image With Image Filename In Another Cell - Excel
    By Angelq117 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-17-2016, 09:38 AM
  3. Macro to set Image as Desktop Background
    By ZEvans12 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-13-2016, 07:01 AM
  4. [SOLVED] Change the background of an image to transparent
    By worthm in forum Excel General
    Replies: 3
    Last Post: 01-07-2015, 02:20 PM
  5. excel macro to save the output image file from website (no change filename)
    By kiwiques in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-28-2014, 11:03 PM
  6. [SOLVED] Change background image on individual multipage userform pages using vba
    By sbrennan970 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-11-2013, 06:50 AM
  7. Replies: 2
    Last Post: 07-02-2013, 03:36 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