Copy sheet to new book without referencing original book

cocopops2001

Board Regular
Joined
Apr 18, 2011
Messages
112
Dear All,

Two problems, one may be simple the other not so simple.

I have a workbook which is essentially a MENU workbook that I do not want anyone to change any values, formulas, formatting, colours etc.

The first problem is that I have buttons along the top of each page with a 'template' underneath. I want users to be able to push the buttons without editing the important part of the sheet I am using the following code in a seperate module:

[/vba]

Sub Unprotect()
ActiveSheet.Protect
ActiveSheet.Range("A11:N70").Locked = True
End Sub

[/vba]


The module is called using this peice of code in the this workbook section.

[/vba]

Private Sub Worksheet_Select()
Unprotect
End Sub

[/vba]

When I run it in the VBA editor it says 'runtime error 1004' unable to set the locked property of the range class. Any ideas?

My second problem is that when I copy these 'templates' into a new workbook the cell references still refer to the original MENU workbook ie ='[menu.xls]Cover Sheet'!$H$51 when i want it to refer to the cover sheet in the new work book.

I am copying the sheets using:

[/vba]

Sub sheetcopy()
ActiveSheet.Range("a11:n70").Copy

'subroutine to open select a workbook in which to place the calc sheet(module6)
OpenCalc


Worksheets.Add after:=Worksheets(Worksheets.Count)
Worksheets(Worksheets.Count).Range("a1").PasteSpecial
Application.CutCopyMode = False
End Sub

[/vba]

the open calc module is:
[/vba]
Sub OpenCalc()

Dim fn
fn = Application.GetOpenFilename 'can add parameters. See help for details.
If fn = False Then
MsgBox "Nothing Chosen"
Else
MsgBox "You chose " & fn
Workbooks.Open fn
End If

End Sub
[/vba]

Any help on this would be great.

Thanks.

 
no, I have only use VBA for a couple of months and only fully started on it this week while trying to get this thing up and running. basically i want the cells to reference the cover sheet in the new active workbook but i have no idea where the active workbook would be as it could be on any machine and used by multiple users. I am maybe at the wrong stage as during the copy sheet process i would like a form where the user can either select a file to use or create a new one.

from this would it be quite simple to store the file name somewhere and then reference this variable in my change links part of the macro?

I am not new to programming but have never really used it in any significant way.
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
If you record a macro what do you get. This is what I got:

Code:
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 20/04/2011 by Andrew
'
'
    ActiveWorkbook.ChangeLink Name:="Book1.xls", NewName:="Book2.xls", Type:= _
        xlExcelLinks
End Sub

The worksheet being referenced does have the same name in both workbooks doesn't it?
 
Upvote 0
i get

Code:
Sub Macro5()
'
' Macro5 Macro
' Macro recorded 20/04/2011 by Stewart Livingston
'

'
    ActiveWorkbook.ChangeLink Name:="intro.xls", NewName:= _
        "M:\spreadsheets\New Microsoft Excel Worksheet.xls", Type:=xlExcelLinks
End Sub


yes the sheet being referenced is the same in the master and in the new book
 
Upvote 0
got it working now, thanks very much for all your help. i had the code the wrong way round. i was trying to paste in the new sheet before checking that a cover sheet existed and if not create one. silly me
 
Upvote 0
the code that was given to me earlier works fine as long as the master file is called 'intro.xls' but i want to put in something that will still work if the master filename is changed i have tried
Code:
ActiveWorkbook.ChangeLink Name:=ThisWorkbook.Name, NewName:=ActiveWorkbook.Name, Type:=xlExcelLinks
but i get a runtime error 1004 "Method 'ChangeLink' of object '_Workbook' failed "

i have also tried
Code:
dim wb as string 
set wb = thisworkbook.name

and put "wb" & ".xls" in place of thisworkbook.name but it gives me the error object required whenever it gets to the line with set wb=
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,719
Members
452,939
Latest member
WCrawford

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