(Solved) – Open a file from a dynamic path in VBA

  • by
(solved)-–-open-a-file-from-a-dynamic-path-in-vba

I have a code that opens a excel file formats and closes. When I use only the network path, the code works perfectly. When I add the dynamic part of the path which is “//mynetworkpath/year-month/complete”, the code doesn’t find the file. So the path is like this: “//mynetworkpath/2019-12/complete”. Could anyone tell me what I’m doing wrong?

Sub format_excel()

Application.ScreenUpdating = False

Dim mypath As String

Dim file As String

mypath = "//mynetworkpath/" & Format(Now, "yyyy-mm") & "https://stackoverflow.com/" & "complete"

file = Dir(mypath & "myfilename_*.xlsx")

If Not IsEmpty(file) Then

   Workbooks.Open (mypath & file)

Leave a Reply

Your email address will not be published. Required fields are marked *