+ Reply to Thread
Results 1 to 7 of 7

How to get the name of the background currently displayed in Excel?

  1. #1
    Registered User
    Join Date
    02-02-2020
    Location
    Brussels
    MS-Off Ver
    2016
    Posts
    22

    How to get the name of the background currently displayed in Excel?

    Hello,

    I have a macro in VBA that is on loop and cycles between many pictures I have in a folder as backgrounds for my spreadsheet.
    I would like if possible to get the name of the background currently displayed so it writes it in a cell of the spreadsheet.

    How could I do that?
    Thanks

    Here is the vba code:

    Please Login or Register  to view this content.
    Last edited by Janna One Trick; 08-08-2021 at 11:07 AM.

  2. #2
    Forum Moderator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    365
    Posts
    19,300

    Re: How to get the name of the background currently displayed in Excel?

    I have done some research on this and there does not appear to be any built-in property that can tell you the name of the file you used to set the background. However, since you are setting the background in your code, why not just add a line of code to show the file name in a cell at the same point where you set the background?
    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    02-02-2020
    Location
    Brussels
    MS-Off Ver
    2016
    Posts
    22

    Re: How to get the name of the background currently displayed in Excel?

    Ha yes indeed it works as intended! Thank you!

    Is there a way to only show the name of the file without the extension?

    It currently displays the full path and the extension:
    D:\Backgrounds\name.jpg

    How to make it display only "name"?

  4. #4
    Valued Forum Contributor
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    669

    Re: How to get the name of the background currently displayed in Excel?

    Quote Originally Posted by 6StringJazzer View Post
    I have done some research on this and there does not appear to be any built-in property that can tell you the name of the file you used to set the background.
    When you insert an image as the sheet background, Excel saves the file with its own internal name. Does not store the name of the source file. The image is stored in an internal folder \xl\media\ with a name such as image1.png. In the internal file \xl\worksheets\_rels\sheet1.xml.rels we find relation Id and path to image , e.g.
    Please Login or Register  to view this content.
    In the file \xl\worksheets\sheet1.xml we find the relation:
    Please Login or Register  to view this content.
    .

    Artik

  5. #5
    Forum Moderator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    365
    Posts
    19,300

    Re: How to get the name of the background currently displayed in Excel?

    Let's try this:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-02-2020
    Location
    Brussels
    MS-Off Ver
    2016
    Posts
    22

    Re: How to get the name of the background currently displayed in Excel?

    It is strange, it gives an error:
    https://i.gyazo.com/552b4d9c5ef8caa2...baff5627e1.png

  7. #7
    Forum Moderator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    365
    Posts
    19,300

    Re: How to get the name of the background currently displayed in Excel?

    Change this declaration as follows

    Please Login or Register  to view this content.
    The way it is declared is Variant, but it is used only as a String so should be declared as String. Also, the Sub expects a String argument so now it will match.

+ 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. I have an excel spreadsheet that is displayed within an iframe.
    By medo82006 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-18-2014, 01:34 PM
  2. [SOLVED] Set number value displayed in cell when certain text value is displayed in another
    By chrisswann in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-18-2013, 09:07 AM
  3. Excel displayed in a userform
    By Spherous in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-31-2013, 01:10 AM
  4. [SOLVED] Excel seeing numbers not displayed in a cell
    By asherwood in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-01-2012, 05:56 PM
  5. Excel dialog is not being displayed
    By jpcdelft in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-02-2011, 07:29 AM
  6. Excel Columns Not Displayed
    By coolio 20061 in forum Excel General
    Replies: 3
    Last Post: 12-13-2006, 09:43 PM
  7. Embedded Excel in PPT - what is the displayed range?
    By JS in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-26-2006, 06:35 PM
  8. Replies: 1
    Last Post: 08-29-2005, 05:25 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