Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10
Default Can I Use VBA to Create New Workbook Without Links?

I stole and then modified the following code. Connected to a button on a
worksheet in my current workbook, it creates a new workbook containing only
one sheet, which is a copy of the old one. (Just before the end, it also
turns off the sheet tabs in the new workbook.):

Sub CopyCoverRequestSheet()
'declare the variables
Dim wb As Workbook
Dim ws As Worksheet
Dim fName
With Application
'prevent unnecessary error messages
..DisplayAlerts = False
'switch off screen updating to speed up code and prevent screen flickering
..ScreenUpdating = False
Set wb = Workbooks.Add
Do
'use inbuilt dialog to prompt for a name, this will only store the name to
be used later
fName = Application.GetSaveAsFilename
'continue until user enters a valid name
Loop Until fName < False
'save the new workbook
ActiveWorkbook.SaveAs Filename:=fName
'copy sheet to new workbook, you must change the sheet to be copied to match
yours
ThisWorkbook.Worksheets("3. Submit Cover & Title Page MS").Copy
befo=Worksheets("Sheet1")
'remove empty sheets
For Each ws In ActiveWorkbook.Worksheets
If ws.Name < ActiveSheet.Name Then ws.Delete
Next ws
'return application to normal
ActiveWindow.DisplayWorkbookTabs = False
..DisplayAlerts = True
..ScreenUpdating = True
End With
'clear memory
Set wb = Nothing
Set ws = Nothing
End Sub

This works really well. My problem, though, is that the new workbook
contains links to the old one. Is there a way to modify this code to sever
links of all types to the old workbook? I've doodled around with the
BreakLinks method, but I keep getting runtime errors. Can anyone help?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Can I Use VBA to Create New Workbook Without Links?

If that sheet that is copied has formulas that refer to other sheets in the
original workbook, you'll end up with links back to that original workbook.

You could convert those formulas (all formulas???) to values.

Maybe just selecting all the cells, edit|copy, edit|paste special values would
be enough???

In xl2003, you can use:
Edit|Links and break the links (converting them to values)

Record a macro when you do either and you'll have the code you need.

Pausert of Nikkeldepaiin wrote:

I stole and then modified the following code. Connected to a button on a
worksheet in my current workbook, it creates a new workbook containing only
one sheet, which is a copy of the old one. (Just before the end, it also
turns off the sheet tabs in the new workbook.):

Sub CopyCoverRequestSheet()
'declare the variables
Dim wb As Workbook
Dim ws As Worksheet
Dim fName
With Application
'prevent unnecessary error messages
.DisplayAlerts = False
'switch off screen updating to speed up code and prevent screen flickering
.ScreenUpdating = False
Set wb = Workbooks.Add
Do
'use inbuilt dialog to prompt for a name, this will only store the name to
be used later
fName = Application.GetSaveAsFilename
'continue until user enters a valid name
Loop Until fName < False
'save the new workbook
ActiveWorkbook.SaveAs Filename:=fName
'copy sheet to new workbook, you must change the sheet to be copied to match
yours
ThisWorkbook.Worksheets("3. Submit Cover & Title Page MS").Copy
befo=Worksheets("Sheet1")
'remove empty sheets
For Each ws In ActiveWorkbook.Worksheets
If ws.Name < ActiveSheet.Name Then ws.Delete
Next ws
'return application to normal
ActiveWindow.DisplayWorkbookTabs = False
.DisplayAlerts = True
.ScreenUpdating = True
End With
'clear memory
Set wb = Nothing
Set ws = Nothing
End Sub

This works really well. My problem, though, is that the new workbook
contains links to the old one. Is there a way to modify this code to sever
links of all types to the old workbook? I've doodled around with the
BreakLinks method, but I keep getting runtime errors. Can anyone help?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10
Default Can I Use VBA to Create New Workbook Without Links?

Thanks for the idea, Dave! I think I'm still stuck, though. As I've been
trying to think this through since my original post, I think the links are
coming from names that I'm inadvertently picking up from the original
workbook, which has a bazillion named cells in it. Do you know if there a
way, in the course of running the copy code, to wipe out all names in the new
workbook?

I must admit to a minor panic--I'm supposed to have something to show at
9:30, and although the links thing probably won't be an issue for the rest of
the team, it's going to bug me a LOT. If you have any more ideas, I'd
appreciate it.

"Dave Peterson" wrote:

If that sheet that is copied has formulas that refer to other sheets in the
original workbook, you'll end up with links back to that original workbook.

You could convert those formulas (all formulas???) to values.

Maybe just selecting all the cells, edit|copy, edit|paste special values would
be enough???

In xl2003, you can use:
Edit|Links and break the links (converting them to values)

Record a macro when you do either and you'll have the code you need.

Pausert of Nikkeldepaiin wrote:

I stole and then modified the following code. Connected to a button on a
worksheet in my current workbook, it creates a new workbook containing only
one sheet, which is a copy of the old one. (Just before the end, it also
turns off the sheet tabs in the new workbook.):

Sub CopyCoverRequestSheet()
'declare the variables
Dim wb As Workbook
Dim ws As Worksheet
Dim fName
With Application
'prevent unnecessary error messages
.DisplayAlerts = False
'switch off screen updating to speed up code and prevent screen flickering
.ScreenUpdating = False
Set wb = Workbooks.Add
Do
'use inbuilt dialog to prompt for a name, this will only store the name to
be used later
fName = Application.GetSaveAsFilename
'continue until user enters a valid name
Loop Until fName < False
'save the new workbook
ActiveWorkbook.SaveAs Filename:=fName
'copy sheet to new workbook, you must change the sheet to be copied to match
yours
ThisWorkbook.Worksheets("3. Submit Cover & Title Page MS").Copy
befo=Worksheets("Sheet1")
'remove empty sheets
For Each ws In ActiveWorkbook.Worksheets
If ws.Name < ActiveSheet.Name Then ws.Delete
Next ws
'return application to normal
ActiveWindow.DisplayWorkbookTabs = False
.DisplayAlerts = True
.ScreenUpdating = True
End With
'clear memory
Set wb = Nothing
Set ws = Nothing
End Sub

This works really well. My problem, though, is that the new workbook
contains links to the old one. Is there a way to modify this code to sever
links of all types to the old workbook? I've doodled around with the
BreakLinks method, but I keep getting runtime errors. Can anyone help?


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Can I Use VBA to Create New Workbook Without Links?

Here are some tools that'll help you:

Bill Manville's FindLink program:
http://www.oaltd.co.uk/MVP/Default.htm

And I like Jan Karel Pieterse's (with Charles Williams and Matthew Henson) Name
Manager:

You can find it at:
NameManager.Zip from http://www.oaltd.co.uk/mvp

=====
There are names that excel uses that you may not want to delete.

I think I'd use the name manager to find the names that get copied over. Then
make a note of them and delete them explicitly.

On error resume next 'in case a future version doesn't have the same names
with yournewworkbook
.names("name1").delete
.names("name2").delete
End with
On error goto 0

But if you find that you can delete all the names without breaking stuff:

Dim myName as name
for each myName in yournewworkbook.names
myName.delete
next myname

But I'd use that NameManager before I did anything.


Pausert of Nikkeldepaiin wrote:

Thanks for the idea, Dave! I think I'm still stuck, though. As I've been
trying to think this through since my original post, I think the links are
coming from names that I'm inadvertently picking up from the original
workbook, which has a bazillion named cells in it. Do you know if there a
way, in the course of running the copy code, to wipe out all names in the new
workbook?

I must admit to a minor panic--I'm supposed to have something to show at
9:30, and although the links thing probably won't be an issue for the rest of
the team, it's going to bug me a LOT. If you have any more ideas, I'd
appreciate it.

"Dave Peterson" wrote:

If that sheet that is copied has formulas that refer to other sheets in the
original workbook, you'll end up with links back to that original workbook.

You could convert those formulas (all formulas???) to values.

Maybe just selecting all the cells, edit|copy, edit|paste special values would
be enough???

In xl2003, you can use:
Edit|Links and break the links (converting them to values)

Record a macro when you do either and you'll have the code you need.

Pausert of Nikkeldepaiin wrote:

I stole and then modified the following code. Connected to a button on a
worksheet in my current workbook, it creates a new workbook containing only
one sheet, which is a copy of the old one. (Just before the end, it also
turns off the sheet tabs in the new workbook.):

Sub CopyCoverRequestSheet()
'declare the variables
Dim wb As Workbook
Dim ws As Worksheet
Dim fName
With Application
'prevent unnecessary error messages
.DisplayAlerts = False
'switch off screen updating to speed up code and prevent screen flickering
.ScreenUpdating = False
Set wb = Workbooks.Add
Do
'use inbuilt dialog to prompt for a name, this will only store the name to
be used later
fName = Application.GetSaveAsFilename
'continue until user enters a valid name
Loop Until fName < False
'save the new workbook
ActiveWorkbook.SaveAs Filename:=fName
'copy sheet to new workbook, you must change the sheet to be copied to match
yours
ThisWorkbook.Worksheets("3. Submit Cover & Title Page MS").Copy
befo=Worksheets("Sheet1")
'remove empty sheets
For Each ws In ActiveWorkbook.Worksheets
If ws.Name < ActiveSheet.Name Then ws.Delete
Next ws
'return application to normal
ActiveWindow.DisplayWorkbookTabs = False
.DisplayAlerts = True
.ScreenUpdating = True
End With
'clear memory
Set wb = Nothing
Set ws = Nothing
End Sub

This works really well. My problem, though, is that the new workbook
contains links to the old one. Is there a way to modify this code to sever
links of all types to the old workbook? I've doodled around with the
BreakLinks method, but I keep getting runtime errors. Can anyone help?


--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Taking specific rows from on workbook to create another workbook Michelle Excel Worksheet Functions 1 May 12th 07 04:54 AM
My workbook links are not updating (its 30,000 KB size workbook). rselena Excel Discussion (Misc queries) 1 August 14th 06 09:14 PM
Faster way to create Links? nander Excel Discussion (Misc queries) 0 February 22nd 06 07:10 PM
create links for formulas weclean Excel Worksheet Functions 0 April 4th 05 10:09 PM
How do I create a workbook that links info in cell to a calendar? JH Excel Worksheet Functions 2 March 30th 05 09:45 PM


All times are GMT +1. The time now is 09:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"