Is there a way of inserting the full pathname instead of the filename when closing and saving a workbook
E.g below
Workbooks("BOOK1.XLS").Close SaveChanges:=true
Workbooks("C:\user\docs\BOOK1.XLS").Close SaveChanges:=true
Reason why I ask is that I've already named all my full pathnames in strings
Workbooks(i).Close SaveChanges:=true
So for each i in array etc
The Workbook object can be used like in your first statement
Workbooks("BOOK1.XLS").Close
because it uses the .Name property (without full path)
The Workbooks.Open
method on the other hand, takes as parameter the full path and file name:
Workbooks.Open "C:\user\docs\BOOK1.XLS"
It can take the file name without a path as well, but it will search for it in the default folder
.
There are 2 options I use to solve similar problems, where all strings include full path and file name:
set a reference to the workbook when you open it:
Set wb = Workbooks.Open("C:\user\docs\BOOK1.XLS")
then you can close it like this
wb.Close SaveChanges:=True
Extract the file name from the string containing both, path and file name:
wbName = Mid(fullName, InStrRev(fullName, "\") + 1)
then you can close it as in your first line:
Workbooks(wbName).Close SaveChanges:=true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With