I’ve made a template with buttons (and macros). By pushing one of the buttons a calculation is done and a chart is generated. Now I want the user to be able to save the worksheet without macros attached (as the calculation is only needed once). The problem is that I don’t know how to do this. I can’t find a ‘SaveAs’ without macros option. Therefore, I entered a button with a macro to copy the contents of the spreadsheet to another workbook and leave it to the user to save the new workbook. Now I have 2 other problems:
1) in some cases the chart is not copied with the rest (what I do is just copying the whole sheet and pasting it). This seems to be very random: sometimes the chart is copied, sometimes not.
2) how do I unlink the reference to the ‘old’ worksheet in the data series of the chart? As I copied the whole sheet, including the data used for the chart, the name of the sheet in the data series can be the new sheet.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Unlink data from worksheet in Chart (Excel 97)
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Unlink data from worksheet in Chart (Excel 97)
- This topic has 11 replies, 4 voices, and was last updated 23 years, 1 month ago.
AuthorTopicWSHans Pottel
AskWoody LoungerMay 14, 2002 at 7:44 am #370865Viewing 1 reply threadAuthorReplies-
WSHansV
AskWoody LoungerMay 14, 2002 at 8:25 am #587884You can copy a whole sheet (as opposed to copying the contents of a sheet) using code like
ActiveWorkbook.Sheets(“Sheet2”).Copy After:=Workbooks(“Workbook2”).Sheets(“Sheet1”)
Doing it this way, all references *within* the sheet should migrate correctly. References to other sheets will still refer to the old workbook, I suppose, but I haven’t tested that.
(of course, you can make this more elegant by using variables for the workbooks and sheets, but this
will give you the basic idea) -
WSHans Pottel
AskWoody LoungerMay 14, 2002 at 9:05 am #587886Thanks for your reply, but this doesn’t work here.
Private Sub CmdCopy_Click() Dim sNameWb1 As String Dim sNameWb2 As String Dim sNameWs1 As String Dim sNameWs2 As String 'original workbook and worksheet sNameWb1 = ActiveWorkbook.Name sNameWs1 = ActiveSheet.Name Workbooks.Add 'new workbook and worksheet sNameWb2 = ActiveWorkbook.Name sNameWs2 = ActiveSheet.Name Workbooks(sNameWb1).Sheets(sNameWs1).Range("A1:N65").Copy _ After:=Workbooks(sNameWb2).Sheets(sNameWs2) End Sub
I always get an object-defined or application-defined error ‘run-time error 1004’ when the copy statement is executed. Using the de######, I checked the names of the workbooks and sheets and everything seems ok, but copying does not work. If I replace After by Destination and add .Range(“A1”) then the sheet is copied but the data series in the chart are still pointing to the original workbook.
-
WSAndrew Cronnolly
AskWoody LoungerMay 14, 2002 at 9:20 am #587887Hans,
The attached code will copy only the worksheets to a new workbook. However any code that is in any of the worksheets will be copied as part of the worksheet . So this is only suitable for reomiving code stored in a general module. There is also code to remove the button that invokes the code, and you should change the name of this from
-
WSHans Pottel
AskWoody LoungerMay 14, 2002 at 9:30 am #587888Thanks Andrew.
However, this will still make appear the “this workbook contains macros” dialog window when opening the file, as the code in the worksheet module is still there. What I hoped to do is just save the file without any code. But this does not seem possible in an easy way. As the buttons are outside the A1:N65 range, I thought to just copy this range and paste it into another (empty) workbook. Seemed to me as the most easy way to go. But then I want to get rid of the link to the original workbook in my copied chart.
Maybe your approach is the way to go. Removing worksheet code requires code. How to get rid of that? -
WSAndrew Cronnolly
AskWoody Lounger -
WSpieterse
AskWoody Lounger -
WSHans Pottel
AskWoody LoungerMay 14, 2002 at 10:28 am #587894Jan Karel,
The problem is that the template has a nice layout, contains logos, the user enters data in the spreadsheet before the calculation etc. The problem is that I didn’t thought of the allergy of the user against the presence of code in the workbook. And in a certain way he is right; after entering the data and doing the calculation, storing the output would be all that is required. Part of the output is the layout and the data entered by the user, part of it are the calculation results. That’s why getting rid of the code when saving the worksheet would be the best way to go.
I think I’ll try Andrew’s solution. It gives me a chance to learn about the VBE. Thanks anyway.
-
WSAndrew Cronnolly
AskWoody LoungerMay 14, 2002 at 10:37 am #587896Hans,
I should have made clear to use the CODE name of sheet in place of Sheet1, as that may be different from the actual sheet name as shown on the sheet tab.
If all your code is in the sheet module, you would need to include the VBE code as well so that it can delete itself.
something like the following at th eend of your code :
With ThisWorkbook.VBProject.VBComponents(Me.CodeName).CodeModule
.DeleteLines 1, .CountOfLines
End WithAndrew
-
WSAndrew Cronnolly
AskWoody LoungerMay 14, 2002 at 10:43 am #587902Hans,
I forgot to include this link to Chip Pearson’s site , which might help if you want to learn about the VBE and coding for it.
Andrew
-
WSHans Pottel
AskWoody LoungerMay 14, 2002 at 11:33 am #587919One of my other questions was how to unlink the data from the original worksheet. After some experimenting I came to this (assuming I have a chart named HPChart in the activeworksheet and 1 data series):
Sub test() ActiveSheet.ChartObjects("HPChart").Activate ActiveChart.ChartArea.Select ActiveChart.SeriesCollection(1).Select Application.SendKeys "{F2}" Application.SendKeys "{F9}" Application.SendKeys "{ENTER}" End Sub
You’ll get into trouble with this if in case of too many data, but for small data sets it works fine. F2 selects the command line, F9 unlinks the data from its range address, using the actual values as such, and enter is needed to make the whole command effective.
Just wanted to share this with you. Thanks to all!
-
-
-
-
-
WSpieterse
AskWoody Lounger
Viewing 1 reply thread -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Microsoft : Edge is better than Chrome
by
Alex5723
1 hour, 53 minutes ago -
The EU launched DNS4EU
by
Alex5723
14 hours, 35 minutes ago -
Cell Phone vs. Traditional Touchtone Phone over POTS
by
280park
4 hours, 55 minutes ago -
Lost access to all my networked drives (shares) listed in My Computer
by
lwerman
20 hours, 1 minute ago -
Set default size for pasted photo to word
by
Cyn
1 day, 2 hours ago -
Dedoimedo tries 24H2…
by
Cybertooth
14 hours, 9 minutes ago -
Windows 11 Insider Preview build 27871 released to Canary
by
joep517
2 days, 1 hour ago -
Windows 11 ad from Campaign Manager in Windows 10
by
Jim McKenna
1 day, 22 hours ago -
Small desktops
by
Susan Bradley
15 hours, 41 minutes ago -
Totally disable Bitlocker
by
CWBillow
18 hours, 35 minutes ago -
Phishers extract Millions from HMRC accounts..
by
Microfix
1 day, 22 hours ago -
Windows 10 22H2 Update today (5 June) says up-to-date but last was 2025-04
by
Alan_uk
3 days, 4 hours ago -
Thoughts on Malwarebytes Scam Guard for Mobile?
by
opti1
23 hours, 43 minutes ago -
Mystical Desktop
by
CWBillow
3 days, 8 hours ago -
Meta and Yandex secretly tracked billions of Android users
by
Alex5723
2 days, 13 hours ago -
MS-DEFCON 2: Do you need that update?
by
Susan Bradley
52 minutes ago -
CD/DVD drive is no longer recognized
by
WSCape Sand
3 days, 23 hours ago -
Windows 11 24H2 Default Apps stuck on Edge and Adobe Photoshop
by
MikeBravo
4 days, 2 hours ago -
North Face and Cartier customer data stolen in cyber attacks
by
Alex5723
4 days ago -
What is wrong with simple approach?
by
WSSpoke36
1 day, 22 hours ago -
Microsoft-Backed Builder.ai Set for Bankruptcy After Cash Seized
by
Alex5723
4 days, 11 hours ago -
Location, location, location
by
Susan Bradley
3 days, 2 hours ago -
Cannot get a task to run a restore point
by
CWBillow
4 days, 13 hours ago -
Frustrating search behavior with Outlook
by
MrJimPhelps
4 days, 3 hours ago -
June 2025 Office non-Security Updates
by
PKCano
4 days, 23 hours ago -
Secure Boot Update Fails after KB5058405 Installed
by
SteveIT
2 hours, 23 minutes ago -
Firefox Red Panda Fun Stuff
by
Lars220
4 days, 23 hours ago -
How start headers and page numbers on page 3?
by
Davidhs
5 days, 10 hours ago -
Attack on LexisNexis Risk Solutions exposes data on 300k +
by
Nibbled To Death By Ducks
4 days, 13 hours ago -
Windows 11 Insider Preview build 26200.5622 released to DEV
by
joep517
5 days, 19 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.