Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Inserting a filename into a cell

Hi
try one of the following formulas (note: the workbook has to be save
before). Just use the formulas as they are shown (don't replace
'filename' with anything else)

File path and file name:
=CELL("filename",A1)

File path only
=LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1),1)-1)

File name only
=MID(CELL("filename",A1),FIND("[",CELL("filename",A1),1)+1,FIND("]",CEL
L("filename",A1),1)-FIND("[",CELL("filename",A1),1)-1)

The sheet name
=RIGHT(CELL("filename",A1),LEN(CELL("filename",A1) )-FIND("]",CELL("file
name",A1),1))


--
Regards
Frank Kabel
Frankfurt, Germany


davidoo2005 wrote:
How can I obtain the name of a file as a string? For instance, in
workbook C:\Documents and Settings\Me\Folder\file1.xls, I would like
file1 to be the string.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Inserting a filename into a cell

Hi
use these formulas directly in your worksheet 8no VBA required).

For a VBA solution simply use something like

sub insert_name()
with activesheet
.range("A1").value=.name
end with
end sub


--
Regards
Frank Kabel
Frankfurt, Germany


davidoo2005 wrote:
Hi,
When I run a program with the codes below I get an error that says
"Compile Error: Function or Sub not defined" that refers to the
function "CELL(".


"Frank Kabel" wrote:

Hi
try one of the following formulas (note: the workbook has to be save
before). Just use the formulas as they are shown (don't replace
'filename' with anything else)

File path and file name:
=CELL("filename",A1)

File path only
=LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1),1)-1)

File name only

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

The sheet name

=RIGHT(CELL("filename",A1),LEN(CELL("filename",A1) )-FIND("]",CELL("file
name",A1),1))


--
Regards
Frank Kabel
Frankfurt, Germany


davidoo2005 wrote:
How can I obtain the name of a file as a string? For instance, in
workbook C:\Documents and Settings\Me\Folder\file1.xls, I would

like
file1 to be the string.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Inserting a filename into a cell

Hi
msgbox activeworkbook.name

--
Regards
Frank Kabel
Frankfurt, Germany


davidoo2005 wrote:
I'm sorry, I think I phrased the question poorly. I have about 2000
spreadsheets each containing a single data table, and I am trying to
compile averages. For each workbook, I take some averages and copy
them into a separate workbook. I would like to label each average I
copy into the separate workbook with the name of the file they came
from. I am wondering if there is a function in VBA that obtains the
file name of the ActiveWorkbook as a string. Thanks!

"Frank Kabel" wrote:

Hi
use these formulas directly in your worksheet 8no VBA required).

For a VBA solution simply use something like

sub insert_name()
with activesheet
.range("A1").value=.name
end with
end sub


--
Regards
Frank Kabel
Frankfurt, Germany


davidoo2005 wrote:
Hi,
When I run a program with the codes below I get an error that says
"Compile Error: Function or Sub not defined" that refers to the
function "CELL(".


"Frank Kabel" wrote:

Hi
try one of the following formulas (note: the workbook has to be
save before). Just use the formulas as they are shown (don't
replace 'filename' with anything else)

File path and file name:
=CELL("filename",A1)

File path only
=LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1),1)-1)

File name only


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

The sheet name


=RIGHT(CELL("filename",A1),LEN(CELL("filename",A1) )-FIND("]",CELL("file
name",A1),1))


--
Regards
Frank Kabel
Frankfurt, Germany


davidoo2005 wrote:
How can I obtain the name of a file as a string? For instance, in
workbook C:\Documents and Settings\Me\Folder\file1.xls, I would

like
file1 to be the string.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Inserting a filename into a cell

That displays the string, but how can I obtain that string value as a string variable?

"Frank Kabel" wrote:

Hi
msgbox activeworkbook.name

--
Regards
Frank Kabel
Frankfurt, Germany


davidoo2005 wrote:
I'm sorry, I think I phrased the question poorly. I have about 2000
spreadsheets each containing a single data table, and I am trying to
compile averages. For each workbook, I take some averages and copy
them into a separate workbook. I would like to label each average I
copy into the separate workbook with the name of the file they came
from. I am wondering if there is a function in VBA that obtains the
file name of the ActiveWorkbook as a string. Thanks!

"Frank Kabel" wrote:

Hi
use these formulas directly in your worksheet 8no VBA required).

For a VBA solution simply use something like

sub insert_name()
with activesheet
.range("A1").value=.name
end with
end sub


--
Regards
Frank Kabel
Frankfurt, Germany


davidoo2005 wrote:
Hi,
When I run a program with the codes below I get an error that says
"Compile Error: Function or Sub not defined" that refers to the
function "CELL(".


"Frank Kabel" wrote:

Hi
try one of the following formulas (note: the workbook has to be
save before). Just use the formulas as they are shown (don't
replace 'filename' with anything else)

File path and file name:
=CELL("filename",A1)

File path only
=LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1),1)-1)

File name only


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

The sheet name


=RIGHT(CELL("filename",A1),LEN(CELL("filename",A1) )-FIND("]",CELL("file
name",A1),1))


--
Regards
Frank Kabel
Frankfurt, Germany


davidoo2005 wrote:
How can I obtain the name of a file as a string? For instance, in
workbook C:\Documents and Settings\Me\Folder\file1.xls, I would
like
file1 to be the string.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Inserting a filename into a cell

Try something like

Dim S As String
S = ActiveWorkbook.Name


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"davidoo2005" wrote in
message
...
That displays the string, but how can I obtain that string

value as a string variable?

"Frank Kabel" wrote:

Hi
msgbox activeworkbook.name

--
Regards
Frank Kabel
Frankfurt, Germany


davidoo2005 wrote:
I'm sorry, I think I phrased the question poorly. I have

about 2000
spreadsheets each containing a single data table, and I am

trying to
compile averages. For each workbook, I take some averages

and copy
them into a separate workbook. I would like to label each

average I
copy into the separate workbook with the name of the file

they came
from. I am wondering if there is a function in VBA that

obtains the
file name of the ActiveWorkbook as a string. Thanks!

"Frank Kabel" wrote:

Hi
use these formulas directly in your worksheet 8no VBA

required).

For a VBA solution simply use something like

sub insert_name()
with activesheet
.range("A1").value=.name
end with
end sub


--
Regards
Frank Kabel
Frankfurt, Germany


davidoo2005 wrote:
Hi,
When I run a program with the codes below I get an error

that says
"Compile Error: Function or Sub not defined" that refers

to the
function "CELL(".


"Frank Kabel" wrote:

Hi
try one of the following formulas (note: the workbook

has to be
save before). Just use the formulas as they are shown

(don't
replace 'filename' with anything else)

File path and file name:
=CELL("filename",A1)

File path only

=LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1),1)-1)

File name only



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

The sheet name



=RIGHT(CELL("filename",A1),LEN(CELL("filename",A1) )-FIND("]",CELL
("file
name",A1),1))


--
Regards
Frank Kabel
Frankfurt, Germany


davidoo2005 wrote:
How can I obtain the name of a file as a string? For

instance, in
workbook C:\Documents and Settings\Me\Folder\file1.xls,

I would
like
file1 to be the string.





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Are there any NON-Visual Basic solutions for inserting a picture based a derived or called filename? The Great Attractor Excel Worksheet Functions 7 May 27th 07 04:38 AM
Cell("filename") doesn't update to new filename when do save as. Louis Excel Worksheet Functions 2 March 22nd 07 07:27 PM
substitute the filename in a cell reference with a string in another cell. flummi Excel Discussion (Misc queries) 11 February 22nd 06 01:14 PM
Filename in a cell phica dk Excel Worksheet Functions 3 November 16th 04 04:14 PM
Inserting Date In Filename Using Macro Mega_-__ Excel Programming 2 November 27th 03 08:51 PM


All times are GMT +1. The time now is 12:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"