Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JT JT is offline
external usenet poster
 
Posts: 234
Default Relative Value Macros

I have a line of code similar to the below:
Workbooks.Open ("C:Test.xls")

Later in the same macro I have the following code:
ActiveCell.FormulaR1C1 = "'Test"

I want to be able to replace the "C:Test.xls" with the next file in this
process and to also use the file name to populate the information in the
second line of code.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Relative Value Macros

Is this a loop to open several books?
"Replace C:\Test.xls with the next file in this process." So are the file
names already put in a column in one workbook, or does each workbook contain
the
name of the next workbook to open?

To get "test" from "C:\Test.xls" you'd simply do this:

public sub MyMacro()
Dim strFilePath As String
Dim strFileName As String

strFilePath = "C:\Files\Test.xls"
strFileName = FileNameFromPath(strFilePath)
' strFileName will then equal Test
end sub

Public Function FileNameFromPath(ByVal strPath As String) As String
If strPath < Empty Then
FileNameFromPath = Mid$(strPath, InStrRev(strPath, "\") + 1, _
(Len(strPath) - InStr(1, strPath, ".")) + 1)
End If
End Function

"JT" wrote:

I have a line of code similar to the below:
Workbooks.Open ("C:Test.xls")

Later in the same macro I have the following code:
ActiveCell.FormulaR1C1 = "'Test"

I want to be able to replace the "C:Test.xls" with the next file in this
process and to also use the file name to populate the information in the
second line of code.

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
Relative Reference Help Macros PhillipsHQ Excel Worksheet Functions 5 August 18th 06 03:29 PM
Macros - Relative cells in Excel BeardT Excel Programming 4 October 14th 04 09:55 PM
Relative References for macros Grace[_4_] Excel Programming 5 June 10th 04 06:09 PM
Excel Relative Macros llockler Excel Programming 1 February 2nd 04 08:44 PM
Relative Cell References in Macros Barry Staples Excel Programming 4 January 25th 04 07:44 AM


All times are GMT +1. The time now is 01:42 AM.

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

About Us

"It's about Microsoft Excel"