Results 1 to 7 of 7

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

Threaded View

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

    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:

    Option Explicit
    
    Const pth = "D:\Backgrounds\"
    Const mfPttrn = "*.jpg"
    
    Private i As Integer, rn As Integer
    Private TimeToRun As Date
    Private fleTbl
    
    Sub file_names()
        Dim fle As String
        i = CreateObject("Scripting.FileSystemObject").GetFolder(pth).Files.Count
        ReDim fleTbl(1 To i, 1 To 2)
        i = 0
        fle = Dir(pth & mfPttrn, vbNormal)
        Do Until fle = ""
            i = i + 1
            fleTbl(i, 1) = i
            fleTbl(i, 2) = pth & fle
            fle = Dir()
        Loop
    End Sub
    
    Sub Macro1()
        Randomize
        rn = Int(UBound(fleTbl, 1) * Rnd + 1)
        ActiveSheet.SetBackgroundPicture Filename:=fleTbl(rn, 2)
        TimeToRun = Now + TimeValue("00:00:10")
        Application.OnTime EarliestTime:=TimeToRun, Procedure:="Macro1"
    End Sub
    Last edited by Janna One Trick; 08-08-2021 at 11:07 AM.

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. [SOLVED] How can zero be displayed in Excel as the first number
    By Kevin in forum Excel General
    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