Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 192
Default File Reference

I want to run this macro for different files. The problem is in the macro it
references the specific file I recorded it in. Is there a way to use this
macro for differnt files without actually going into the code each time? The
file name that will vary is "DRPT BCA Model 2009002.xls"

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 10/15/2008 by HDR
'

'
Windows("REF BCA - Final Model Template revised emissions.xls").Activate
Range("C12:AJ15").Select
Selection.Copy
Windows("DRPT BCA Model 2009002.xls").Activate
Range("C12").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Sheets("Raw Default Values").Select
ActiveWindow.SmallScroll Down:=-13
Range("E30").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "0.05"
Range("E31").Select
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default File Reference

If you activate the worksheet that gets pasted before you start the macro, then
you could do something like:

Option Explicit
Sub Macro1A()
Dim RngToCopy As Range
Dim DestCell As Range

Set RngToCopy = Workbooks("REF BCA - Final Model " _
& "Template revised emissions.xls") _
.Worksheets("somesheetnamehere").Range("C12:AJ15")

Set DestCell = ActiveSheet.Range("c12")

RngToCopy.Copy
DestCell.PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False

Worksheets("Raw Default Values").Range("E30").Value = 0.05

End Sub

You'll have to change somesheetnamehere to the sheet that holds the range that
gets copied.

nick wrote:

I want to run this macro for different files. The problem is in the macro it
references the specific file I recorded it in. Is there a way to use this
macro for differnt files without actually going into the code each time? The
file name that will vary is "DRPT BCA Model 2009002.xls"

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 10/15/2008 by HDR
'

'
Windows("REF BCA - Final Model Template revised emissions.xls").Activate
Range("C12:AJ15").Select
Selection.Copy
Windows("DRPT BCA Model 2009002.xls").Activate
Range("C12").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Sheets("Raw Default Values").Select
ActiveWindow.SmallScroll Down:=-13
Range("E30").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "0.05"
Range("E31").Select
End Sub


--

Dave Peterson
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
Linking to another file using file reference typed cell Steven Excel Worksheet Functions 3 April 5th 08 03:15 AM
cross-reference data from one file to another file Zancouth Excel Discussion (Misc queries) 1 May 30th 06 11:25 AM
File reference TJW JR Excel Worksheet Functions 3 January 10th 06 02:51 PM
How do I reference external data from a file, file name found in . Clux Excel Discussion (Misc queries) 1 February 10th 05 10:52 PM
copy/paste from one file to another without file name reference slvrblt Excel Discussion (Misc queries) 4 February 6th 05 08:57 PM


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