macro button refers to prev. workbook

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
 
D

Dave Peterson

See one guess at your other post.
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top