ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro button refers to prev. workbook (https://www.excelbanter.com/excel-programming/276856-macro-button-refers-prev-workbook.html)

Maja

macro button refers to prev. workbook
 
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

Dave Peterson[_3_]

macro button refers to prev. workbook
 
See one guess at your other post.

Maja wrote:

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


--

Dave Peterson



All times are GMT +1. The time now is 12:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com