T
T
ti_zh_vrach2021-03-01 22:19:29
Visual Basic
ti_zh_vrach, 2021-03-01 22:19:29

How to open a file with a dynamic name using VBA?

It was not possible to collect a working answer in Google.
I have a macro that processes a file with the current date in the title:

Dim my_file As Worksheet
Set my_file = Workbooks.Open(Filename:=ThisWorkbook.Path & "\important file" & Date & ".xlsx").Sheets(1)
'do anything
Workbooks("important file" & Date & ".xlsx").Close SaveChanges:=False

How can a file be opened with any character set instead of Date? And if you get .xls?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
John Smith, 2021-03-02
@ti_zh_vrach

- read a list of files from a folder
- check if the beginning of the file name matches "important file"
- process the files from the received list with your macro in turn, if there are several of them

B
BasiC2k, 2021-03-02
@BasiC2k

Do you mean it will fall? Where do these files come from? Or do you randomly take the name of the file and try to open it?
Explain a little more please.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question