Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Insert macro using current workbook

I have a macro that I'd like to use in a workbook whose name changes each
month. It inserts a column in the left most column and opens a specific file
to do a vlookup. In this example, my code is in the file
Windows("june09apdist.xls") but I'd like for it to be in whatever file that
I'm currently working in regardless of the name. Thanks in advance!

ActiveCell.Columns("A:A").EntireColumn.Select
Selection.Insert Shift:=xlToRight
Workbooks.Open FileName:= _
"S:\DFS-Jaffa-WTFiles\HBI Department Naming Convention\HBI
Department Names 01062009.xls"
Windows("jun09apdist.xls").Activate
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[9],'[HBI Department Names 01062009.xls]FY09
Dates'!R1C1:R368C2,2,0)"
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Insert macro using current workbook

'Reference the workbook object

Dim wb As Workbook
Set wb = ActiveWorkbook

'I havent changed the code from here

ActiveCell.Columns("A:A").EntireColumn.Select
Selection.Insert Shift:=xlToRight
Workbooks.Open Filename:= _
"S:\DFS-Jaffa-WTFiles\HBI Department Naming Convention\HBI " & _
"Department Names 01062009.xls"

'change
wb.Activate

ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[9],'[HBI Department Names 01062009.xls]FY09 "
Dates '!R1C1:R368C2,2,0)"


If this post helps click Yes
---------------
Jacob Skaria


"Metro" wrote:

I have a macro that I'd like to use in a workbook whose name changes each
month. It inserts a column in the left most column and opens a specific file
to do a vlookup. In this example, my code is in the file
Windows("june09apdist.xls") but I'd like for it to be in whatever file that
I'm currently working in regardless of the name. Thanks in advance!

ActiveCell.Columns("A:A").EntireColumn.Select
Selection.Insert Shift:=xlToRight
Workbooks.Open FileName:= _
"S:\DFS-Jaffa-WTFiles\HBI Department Naming Convention\HBI
Department Names 01062009.xls"
Windows("jun09apdist.xls").Activate
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[9],'[HBI Department Names 01062009.xls]FY09
Dates'!R1C1:R368C2,2,0)"
End Sub

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 to Insert Current Date into cell - Macro to "Save As" Guy[_2_] Excel Worksheet Functions 4 December 12th 08 09:20 PM
Refering to the current workbook in a macro tpeter Excel Programming 1 August 6th 07 04:38 PM
how can i get a macro in personal.xls to know my current workbook? [email protected] Excel Programming 2 August 3rd 06 09:23 PM
Macro to insert Current Time into protected cell [email protected] Excel Programming 1 July 13th 05 10:30 AM
Help with Macro or VBA script - Insert current Time/Date for different records [email protected] Excel Programming 5 June 8th 05 03:37 PM


All times are GMT +1. The time now is 07:30 PM.

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"