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.
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
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 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
-
Office gets current release
by
Susan Bradley
14 minutes ago -
FBI: Still Using One of These Old Routers? It’s Vulnerable to Hackers
by
Alex5723
11 hours, 16 minutes ago -
Windows AI Local Only no NPU required!
by
RetiredGeek
8 hours ago -
Stop the OneDrive defaults
by
CWBillow
12 hours, 5 minutes ago -
Windows 11 Insider Preview build 27868 released to Canary
by
joep517
22 hours ago -
X Suspends Encrypted DMs
by
Alex5723
1 day ago -
WSJ : My Robot and Me AI generated movie
by
Alex5723
1 day ago -
Botnet hacks 9,000+ ASUS routers to add persistent SSH backdoor
by
Alex5723
1 day, 1 hour ago -
OpenAI model sabotages shutdown code
by
Cybertooth
1 day, 1 hour ago -
Backup and access old e-mails after company e-mail address is terminated
by
M W Leijendekker
13 hours, 54 minutes ago -
Enabling Secureboot
by
ITguy
20 hours, 54 minutes ago -
Windows hosting exposes additional bugs
by
Susan Bradley
1 day, 9 hours ago -
No more rounded corners??
by
CWBillow
1 day, 5 hours ago -
Android 15 and IPV6
by
Win7and10
19 hours, 12 minutes ago -
KB5058405 might fail to install with recovery error 0xc0000098 in ACPI.sys
by
Susan Bradley
1 day, 22 hours ago -
T-Mobile’s T-Life App has a “Screen Recording Tool” Turned on
by
Alex5723
2 days ago -
Windows 11 Insider Preview Build 26100.4202 (24H2) released to Release Preview
by
joep517
1 day, 19 hours ago -
Windows Update orchestration platform to update all software
by
Alex5723
2 days, 8 hours ago -
May preview updates
by
Susan Bradley
1 day, 19 hours ago -
Microsoft releases KB5061977 Windows 11 24H2, Server 2025 emergency out of band
by
Alex5723
1 day, 10 hours ago -
Just got this pop-up page while browsing
by
Alex5723
2 days ago -
KB5058379 / KB 5061768 Failures
by
crown
1 day, 21 hours ago -
Windows 10 23H2 Good to Update to ?
by
jkitc
23 hours, 27 minutes ago -
At last – installation of 24H2
by
Botswana12
2 days, 23 hours ago -
MS-DEFCON 4: As good as it gets
by
Susan Bradley
46 minutes ago -
RyTuneX optimize Windows 10/11 tool
by
Alex5723
3 days, 11 hours ago -
Can I just update from Win11 22H2 to 23H2?
by
Dave Easley
1 day, 10 hours ago -
Limited account permission error related to Windows Update
by
gtd12345
4 days, 1 hour ago -
Another test post
by
gtd12345
4 days, 1 hour ago -
Connect to someone else computer
by
wadeer
2 hours, 36 minutes 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.