PC Review


Reply
Thread Tools Rate Thread

how to change the workbook name in a macro when the name us changed

 
 
a.karatas@gmail.com
Guest
Posts: n/a
 
      6th Mar 2007
Hello,

The following macro was build by me, with the recorder and help from
this site.

I have a problem when I change the workbook name into a higher
version. for example if the workbook is named TVA basic V6.06 and is
changed into V7.01 the macro don't work till I manually change the
name. Is there a method to overcome this problem ie that the search
value changes automatically when the workbook name is changed.

thanks in advance.



Sub Button4_Click()
Dim a As Integer
Dim c As Variant

Warn = "You are going to insert formulas in the OLAP extract. "
Warn = Warn & " Would like the formulas to be inserted. Continue?"
Ans = MsgBox(Warn, vbYesNo)
If Ans = vbYes Then
Application.ScreenUpdating = False
Workbooks.Open Filename:= _
"W:\Finance Divisional\OLAP\Reporting\Territory reporting\TVA
workfile\Factory_by_productcode.xls"
Sheets("factory").Select
Sheets("factory").Copy Before:=Workbooks("TVA basic V6.06.xls"). _
Sheets(34)
Sheets("OLAP extract").Select

a = 2
Range("ec" & a).Select
While Not IsEmpty(Range("ec" & a).Offset(0, -109).Value) '<> ""
Range("ec" & a).Value = "=vlookup(v" & a & " ,markets!
R3c1:r66c3,3,false)"
Range("ed" & a).Value = "=+Assumptions!R1C4"
Range("ee" & a).Value = "=vlookup(s" & a & " ,factory!
R2c2:r5000c26,24,false)"
Range("DU" & a).Value = "=CN" & a & "-DY" & a
Range("DV" & a).Value = "=CO" & a & "-DZ" & a
Range("DW" & a).Value = "=CP" & a & "-EA" & a
a = a + 1

Wend
Cells.Select
Cells.EntireColumn.AutoFit
Application.ScreenUpdating = True
Columns("eC:ef").Select
Selection.Replace What:="'", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Columns("ee:ee").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Sheets("factory").Select
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.delete
Application.DisplayAlerts = True
Sheets("OLAP extract").Select
Range("ec2").Select

End If

End Sub

 
Reply With Quote
 
 
 
 
paul.robinson@it-tallaght.ie
Guest
Posts: n/a
 
      6th Mar 2007
Hi
Looks like your target workbook is already open so try this this

Sub Button4_Click()
Dim a As Integer
Dim c As Variant
Dim TargetWB as Workbook

Set TargetWB = Activeworkbook ' This is Workbooks("TVA basic
V6.06.xls"), assumed to be active
Warn = "You are going to insert formulas in the OLAP extract. "
Warn = Warn & " Would like the formulas to be inserted. Continue?"
Ans = MsgBox(Warn, vbYesNo)
If Ans = vbYes Then
Application.ScreenUpdating = False
Workbooks.Open Filename:= _
"W:\Finance Divisional\OLAP\Reporting\Territory reporting\TVA
workfile\Factory_by_productcode.xls"
Sheets("factory").Select
Sheets("factory").Copy Before:=TargetWB. _
Sheets(34)
Sheets("OLAP extract").Select
etc


regards
Paul


On Mar 6, 11:28 am, a.kara...@gmail.com wrote:
> Hello,
>
> The following macro was build by me, with the recorder and help from
> this site.
>
> I have a problem when I change the workbook name into a higher
> version. for example if the workbook is named TVA basic V6.06 and is
> changed into V7.01 the macro don't work till I manually change the
> name. Is there a method to overcome this problem ie that the search
> value changes automatically when the workbook name is changed.
>
> thanks in advance.
>
> Sub Button4_Click()
> Dim a As Integer
> Dim c As Variant
>
> Warn = "You are going to insert formulas in the OLAP extract. "
> Warn = Warn & " Would like the formulas to be inserted. Continue?"
> Ans = MsgBox(Warn, vbYesNo)
> If Ans = vbYes Then
> Application.ScreenUpdating = False
> Workbooks.Open Filename:= _
> "W:\Finance Divisional\OLAP\Reporting\Territory reporting\TVA
> workfile\Factory_by_productcode.xls"
> Sheets("factory").Select
> Sheets("factory").Copy Before:=Workbooks("TVA basic V6.06.xls"). _
> Sheets(34)
> Sheets("OLAP extract").Select
>
> a = 2
> Range("ec" & a).Select
> While Not IsEmpty(Range("ec" & a).Offset(0, -109).Value) '<> ""
> Range("ec" & a).Value = "=vlookup(v" & a & " ,markets!
> R3c1:r66c3,3,false)"
> Range("ed" & a).Value = "=+Assumptions!R1C4"
> Range("ee" & a).Value = "=vlookup(s" & a & " ,factory!
> R2c2:r5000c26,24,false)"
> Range("DU" & a).Value = "=CN" & a & "-DY" & a
> Range("DV" & a).Value = "=CO" & a & "-DZ" & a
> Range("DW" & a).Value = "=CP" & a & "-EA" & a
> a = a + 1
>
> Wend
> Cells.Select
> Cells.EntireColumn.AutoFit
> Application.ScreenUpdating = True
> Columns("eC:ef").Select
> Selection.Replace What:="'", Replacement:="", LookAt:=xlPart, _
> SearchOrder:=xlByRows, MatchCase:=False
> Columns("ee:ee").Select
> Selection.Copy
> Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
> SkipBlanks:= _
> False, Transpose:=False
> Sheets("factory").Select
> Application.CutCopyMode = False
> ActiveWindow.SelectedSheets.delete
> Application.DisplayAlerts = True
> Sheets("OLAP extract").Select
> Range("ec2").Select
>
> End If
>
> End Sub



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Workbook change event when tab color changed? Barb Reinhardt Microsoft Excel Programming 0 17th Oct 2008 10:13 PM
Using Macro, how can I check if an opened workbook was changed ? =?Utf-8?B?TWFjcm8gdG8gY2hlY2sgaWYgYSB3b3JrYm9vayBo Microsoft Excel Programming 2 15th Aug 2006 01:10 PM
run macro every time page field change is changed paulbrown Microsoft Excel Programming 1 27th Jul 2006 02:14 PM
Macro to change worksheets in the same workbook James C Microsoft Excel Misc 2 19th Oct 2005 08:04 PM
Macro Name problem when I change workbook name? Mike Microsoft Excel Programming 4 26th Jan 2005 02:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:35 AM.