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

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Juan Pablo González

MrExcel MVP
Joined
Feb 8, 2002
Messages
11,959
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

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
66,510
Office Version
  1. 365
Platform
  1. Windows
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

Tompa70

New Member
Joined
Jan 16, 2004
Messages
4
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

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
66,510
Office Version
  1. 365
Platform
  1. Windows
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,186,368
Messages
5,957,455
Members
438,306
Latest member
Crystal_Blue

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
Top