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
Bookmarks