Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

save workbook macro

Status
Not open for further replies.

xxentric

Technical User
Oct 14, 2009
35
US
I have 2 workbooks, book1 and book2

If book1 has a macro that will ...

1. open book2
2. copy and paste cells from book1 to book2
3. then close book 2

Is there a way to change it so that before closing book2 it will save book2 as whatever value is in book1's cell A5 ?
 
Yes. Somethoing like:
Code:
Sub Macro2()
Dim wbkTarget As Workbook
Set wbkTarget = Workbooks.Open("C:\Users\Gavin\Documents\Book2.xls")

ThisWorkbook.Sheets("sheet1").Range("A6:F14").Copy _
        Destination:=wbkTarget.ActiveSheet.Range("A2")
Application.CutCopyMode = False

wbkTarget.SaveAs Filename:=wbkTarget.Path + "\" + ThisWorkbook.Sheets("sheet1").Range("A5").Value, _
        FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False
        
wbkTarget.Close
End Sub
(Next time why not post the (relevant bit of the) code that you have already)

Gavin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top