ThisWorkbook.name

Seamus2626
Seamus2626 used Ask the Experts™
on
Hi, i have this formula in the VBA editor

.Range("U1").Formula = DateSerial(Mid(ThisWorkbook.Name, 13, 4), Mid(ThisWorkbook.Name, 11, 2), Mid(ThisWorkbook.Name, 9, 2))

The code opens another file which im trying to read the date off, one of the problems, is that because the above formula is in the editor of my core spreadsheet, thats spreadsheet name its trying to read. So i need it to be amended so it can read the active workbooks name

Thanks
Seamus
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Dim wk as Workbook
Set wk = ActiveWorkbook
Commented:
Then you can reference the workbook like this:

.Range("U1").Formula = DateSerial(Mid(wk.Name, 13, 4), Mid(wk.Name, 11, 2), Mid(wk.Name, 9, 2))

Author

Commented:
Excellent, thanks Jppinto!

Seamus

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial