Adding worksheet in another workbook

Tompa70

New Member
Joined
Jan 16, 2004
Messages
4
Hi,

I have 2 workbooks and I want to add a sheet in the 2nd workbook and name the new sheet from a cell in the 1st workbook

Code after recording:

Sub veckonummer()
Range("R33").Select
Application.CutCopyMode = True
Selection.Copy
Windows("Kopia 2004.xls").Activate
ActiveSheet.Select
Application.CutCopyMode = True
ActiveSheet.Name = "0401"
Range("B1").Select
ActiveWorkbook.Save
End Sub

This row is hardcoded I want it to be as referens so if I change the "0401" it will name it according to the change.
ActiveSheet.Name = "0401"


/Thomas
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi, welcome to the board.

Is this what you're looking for ?

Code:
Sub SaveOtherBook()
    With Workbooks("Kopia 2004.xls")
        .Sheets(1).Name = Range("R33").Value     'Change the name of the first sheet to the value of cell R33
        .Save    'Save that workbook
    End With
End Sub
 
Upvote 0
How about something like:

Code:
Sub veckonummer()

    Dim myName As String
    Range("R33").Select
    myName = Range("R33").Value
    Windows("Kopia 2004.xls").Activate
    ActiveSheet.Name = myName
    Range("B1").Select
    ActiveWorkbook.Save

End Sub
 
Upvote 0
Thx for the fast answers.

Both examples works fine though they change the name of an existing sheet, I want it to add a new sheet in the 2nd workbook with the value in "R33" wich changes every week. I got around to it finally.
 
Upvote 0
Simply add the line "Sheets.Add":

Code:
Sub veckonummer()

    Dim myName As String
    Range("R33").Select
    myName = Range("R33").Value
    Windows("Kopia 2004.xls").Activate
    Sheets.Add
    ActiveSheet.Name = myName
    Range("B1").Select
    ActiveWorkbook.Save

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,552
Messages
6,114,278
Members
448,560
Latest member
Torchwood72

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top