Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Enter File name in cell

I have a macro to open a file and I want to enter the file name from which
macro is run to a cell in opened file.

If I open abc.xls from file xyz.xls, then I want value of cell F2 in abc.xls
to be xyz
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Enter File name in cell

Sub test()
Dim sFile As String
Dim ws As Worksheet
Dim wb As Workbook
sFile = "C:\Documents and Settings\Owner\My Documents\abc.xls"

On Error Resume Next
Set wb = Workbooks.Open(sFile)
On Error GoTo 0

If wb Is Nothing Then
MsgBox "File not found" & vbCr & sFile
Exit Sub
End If

Set ws = wb.Worksheets("Sheet2")
ws.Range("F2") = ThisWorkbook.Name
ws.Activate

End Sub

Regards,
Peter T

"Kashyap" wrote in message
...
I have a macro to open a file and I want to enter the file name from which
macro is run to a cell in opened file.

If I open abc.xls from file xyz.xls, then I want value of cell F2 in
abc.xls
to be xyz



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Enter File name in cell

Workbooks.Open Filename:= _
"C:\Users\OssieMac\Documents\Excel\Test Macros\ABC.xls"

ActiveWorkbook.Sheets("Sheet1").Range("F2") = ThisWorkbook.Name

--
Regards,

OssieMac


"Kashyap" wrote:

I have a macro to open a file and I want to enter the file name from which
macro is run to a cell in opened file.

If I open abc.xls from file xyz.xls, then I want value of cell F2 in abc.xls
to be xyz

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
Browse For a File or Path and enter in a cell D. Jones Excel Discussion (Misc queries) 5 November 9th 07 04:07 PM
Enter multiple numbers in a cell so total shows when enter keypres newbie Excel Worksheet Functions 2 August 19th 07 12:23 PM
How do I enter a wave sound file into an excel cell? dkimball Excel Discussion (Misc queries) 2 March 28th 05 08:35 PM
how formatting CSV file to get alt-enter text in one cell sylvain[_2_] Excel Programming 0 February 5th 04 11:03 AM
embed <alt<enter for multiline cell in a CSV file John Lopez Excel Programming 3 October 14th 03 03:41 PM


All times are GMT +1. The time now is 05:42 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"