Solved

insert the excel file name into a range of cells

Posted on 2014-10-06
8
535 Views
Last Modified: 2014-10-19
I would like to have a macro that would insert the name of the open file (example: DMAP_10-14.xlsx) into a range of cells
0
Comment
Question by:Dan Purcell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 12

Expert Comment

by:James Elliott
ID: 40363934
Open your VB Editor (Alt+F11)

Insert a new module

Paste the following code

Option Explicit

Public Function MyName() As String

    MyName = ThisWorkbook.Name

End Function

Open in new window


Save your workbook.

Use in any cell(s) like this:

=MyName()
0
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 250 total points
ID: 40363936
Why not use a formula instead of VBA?

=MID(CELL("filename"),FIND("[",CELL("filename"))+1,FIND("]",CELL("filename"))-FIND("[",CELL("filename"))-1)

Open in new window

0
 
LVL 27

Assisted Solution

by:Glenn Ray
Glenn Ray earned 250 total points
ID: 40364028
I like Phillip's solution, but if you indeed need the name of the active file inserted as a value in cells, then the VBA line would be:
Range(range_reference).Value = ActiveWorkbook.Name
where range_reference is either a specific cell (ex., "A2") or range of cells (ex., "A2, B4").  You could also use the cells(r,c) method if you wished.

-Glenn
0
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

Author Closing Comment

by:Dan Purcell
ID: 40364130
Thanks, I did want it as a macro!
0
 
LVL 12

Expert Comment

by:James Elliott
ID: 40364334
Eh?
0
 

Author Comment

by:Dan Purcell
ID: 40373107
I tried running it and couldn't get it to work. You can give him point's, I certainly didn't mean anything personal.
0

Featured Post

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question