macro button refers to prev. workbook?

  • Thread starter Thread starter Maja
  • Start date Start date
M

Maja

Hi,

When I create a macro in Excel, and assign a button to it, it works
fine the first time, but when I re-open the workbook for a second
time, and try to run the macro again, the macro seems to refer to the
previous workbook...For some reason, the macro saves the name of the
previous workbook...



Sub test()
'

Dim name As String
Dim adress As String


Sheets("sheet1").Select
Range("A1").Select

name = ActiveSheet.Range("B6").Value
adress = ActiveSheet.Range("B4").Value


ActiveWorkbook.SaveAs Filename:="C:\WINDOWS\Desktop\Temp\" & name
& "_map" & adress & "_" & ".xls", FileFormat:=xlNormal, Password:="",
WriteResPassword:=""

MsgBox ("done")
End Sub

maybe somebody can help?
thanks in advance,
Maja
 
Hi,

maybe you can try another way to do the same task taht
you are looking to perform:

Perhaps the reason is that you are saving a copy of your
file, bout your first file is different of the copy.
Maybe if you save the first file before you save a copy
of it, the first one and the second will be the same

gook luck,

Leonardo.
 
If you use a commandbutton from the controltoolbox toolbar, it might be easier.

But you don't assign a macro to these. Just double click on it and you'll be
taken to where the code should be placed.

But you can just call your old macro from that code:

Option Explicit
Private Sub CommandButton1_Click()
Call Test
End Sub

Or you could assign the macro to the button again.

worksheets("sheet1").buttons("button 1").onaction _
= thisworkbook.name & "!test"
 
Back
Top