Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,069
Default File Names within a Macro Function

I am trying to create a generic macro that will run a serious of various
commands from one file to another file. The trick is "File A's" name changes
daily. For instance "File A 12_2", "File A 12_3", "File A 12_4", ETC.... Is
there a way to
tell the macro to run off of File A even though the name changes daily?


Sub Amazing()
'
' Amazing Macro
' Macro recorded 12/4/2008 by John
'
' Keyboard Shortcut: Option+Cmd+e
'
Windows("File A 12_2.xls").Activate
Sheets("Agent").Select
Rows("6:2000").Select
Selection.AutoFilter
Selection.AutoFilter Field:=5, Criteria1:="total"
Selection.Sort Key1:=Range("D7"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Selection.AutoFilter Field:=4, Criteria1:="BOB"
Rows("7:2000").Select
Application.CutCopyMode = False
Selection.Copy
Windows("File B.xls").Activate
Range("A3").Select
ActiveSheet.Paste
Windows("File A 12_2.xls").Activate
Selection.AutoFilter Field:=4, Criteria1:="Joe"
Rows("7:2000").Select
Application.CutCopyMode = False
Selection.Copy
Windows("File B.xls").Activate
Range("A5").Select
ActiveSheet.Paste
Windows("File A 12_2.xls").Activate


This is an example of the coding I am trying to use. File A's name changes
every day. I want to be able to maybe put a general file name or command in
place of "File A" that would allow me to run this macro on the open file. I
would open "File A 12_4" and run the macro and it would pull the info from
the report and place it on File B. With File B the macro will rewrite over
the previous information. Any help????
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,346
Default File Names within a Macro Function

Hi,

it seems that there is a pattern he
Windows("File A 12_2.xls").Activate
If this macro runs on 12/3 or 12/2 consistently then

myName="File A "&MONTH(NOW())&"_"&DAY(NOW())&".xls"
Windows(myName).Activate

--
If this helps, please click the Yes button

Cheers,
Shane Devenshire


"John" wrote:

I am trying to create a generic macro that will run a serious of various
commands from one file to another file. The trick is "File A's" name changes
daily. For instance "File A 12_2", "File A 12_3", "File A 12_4", ETC.... Is
there a way to
tell the macro to run off of File A even though the name changes daily?


Sub Amazing()
'
' Amazing Macro
' Macro recorded 12/4/2008 by John
'
' Keyboard Shortcut: Option+Cmd+e
'
Windows("File A 12_2.xls").Activate
Sheets("Agent").Select
Rows("6:2000").Select
Selection.AutoFilter
Selection.AutoFilter Field:=5, Criteria1:="total"
Selection.Sort Key1:=Range("D7"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Selection.AutoFilter Field:=4, Criteria1:="BOB"
Rows("7:2000").Select
Application.CutCopyMode = False
Selection.Copy
Windows("File B.xls").Activate
Range("A3").Select
ActiveSheet.Paste
Windows("File A 12_2.xls").Activate
Selection.AutoFilter Field:=4, Criteria1:="Joe"
Rows("7:2000").Select
Application.CutCopyMode = False
Selection.Copy
Windows("File B.xls").Activate
Range("A5").Select
ActiveSheet.Paste
Windows("File A 12_2.xls").Activate


This is an example of the coding I am trying to use. File A's name changes
every day. I want to be able to maybe put a general file name or command in
place of "File A" that would allow me to run this macro on the open file. I
would open "File A 12_4" and run the macro and it would pull the info from
the report and place it on File B. With File B the macro will rewrite over
the previous information. Any help????

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,069
Default File Names within a Macro Function

I think this should help but "file a 12_2" changes daily. The 12_2 part is
based on the day. I want to run this macro from "File A" daily and the date
part of the file will change every day. How can I make it work based on the
file name changing daily. The first part of the file will not change just the
date. Also where in the macro do I put the command below?

"Shane Devenshire" wrote:

Hi,

it seems that there is a pattern he
Windows("File A 12_2.xls").Activate
If this macro runs on 12/3 or 12/2 consistently then

myName="File A "&MONTH(NOW())&"_"&DAY(NOW())&".xls"
Windows(myName).Activate

--
If this helps, please click the Yes button

Cheers,
Shane Devenshire


"John" wrote:

I am trying to create a generic macro that will run a serious of various
commands from one file to another file. The trick is "File A's" name changes
daily. For instance "File A 12_2", "File A 12_3", "File A 12_4", ETC.... Is
there a way to
tell the macro to run off of File A even though the name changes daily?


Sub Amazing()
'
' Amazing Macro
' Macro recorded 12/4/2008 by John
'
' Keyboard Shortcut: Option+Cmd+e
'
Windows("File A 12_2.xls").Activate
Sheets("Agent").Select
Rows("6:2000").Select
Selection.AutoFilter
Selection.AutoFilter Field:=5, Criteria1:="total"
Selection.Sort Key1:=Range("D7"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Selection.AutoFilter Field:=4, Criteria1:="BOB"
Rows("7:2000").Select
Application.CutCopyMode = False
Selection.Copy
Windows("File B.xls").Activate
Range("A3").Select
ActiveSheet.Paste
Windows("File A 12_2.xls").Activate
Selection.AutoFilter Field:=4, Criteria1:="Joe"
Rows("7:2000").Select
Application.CutCopyMode = False
Selection.Copy
Windows("File B.xls").Activate
Range("A5").Select
ActiveSheet.Paste
Windows("File A 12_2.xls").Activate


This is an example of the coding I am trying to use. File A's name changes
every day. I want to be able to maybe put a general file name or command in
place of "File A" that would allow me to run this macro on the open file. I
would open "File A 12_4" and run the macro and it would pull the info from
the report and place it on File B. With File B the macro will rewrite over
the previous information. Any help????

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
Macro File Names John Excel Worksheet Functions 2 December 5th 08 06:27 AM
Macro File Names John Excel Worksheet Functions 1 December 5th 08 06:23 AM
Open Excel file get error with file names that have spaces in the Kozmo Setting up and Configuration of Excel 6 October 29th 08 02:51 AM
Need a macro to include file names in a folder to excel sheet anil Excel Discussion (Misc queries) 0 March 12th 07 09:10 AM
VBA: syntax to review macro names in a file? [email protected] Excel Discussion (Misc queries) 2 September 7th 05 10:01 PM


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