Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Convert formulas to values on save

I have a template which draws values from formulas that reference other
workbooks. Is there a way, on save, to convert all formulas to values so the
new workbook is a 'snapshot' that can be distributed without needing the
reference to the linked files?

TIA, Steve
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Convert formulas to values on save

Steve,

My approach would be to copy each worksheet to a new workbook. (This
prevents any code staying with the workbook.)

Just record code:
Creat a new workbook
Copy a worksheet in the template
Paste Special Values to the next workbook

Repeat for all sheets you want.

Than modify the code.

You can set the code to copy/paste simple ranges, or entire worksheets.

You can loop through all the worksheets (if you have multiple worksheets.


You can put the code in a standard module or you can put it into the
ThisWorkbook Module.
(This sample only copy all the cells on the active sheet and replaces the
formulas with values.)

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Cells.Copy
Cells.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
End Sub

Let us know if this helps...

--
steveB

Remove "AYN" from email to respond
"Steve B" wrote in message
...
I have a template which draws values from formulas that reference other
workbooks. Is there a way, on save, to convert all formulas to values so
the
new workbook is a 'snapshot' that can be distributed without needing the
reference to the linked files?

TIA, Steve



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Convert formulas to values on save

One way:

Copy the following sub into the "ThisWorkbook" module (NOTE: edit the sheet
name appropriately):

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Call ReplaceFormulasWithValues("Sheet1") '<change to your sheet name
End Sub

Then copy the following function into a normal module:

Public Function ReplaceFormulasWithValues(argSheetName As String)
'REPLACE SHEET CONTENTS WITH VALUES
Dim sSelection As String
Sheets(argSheetName).Activate
sSelection = Selection.Address
Cells.Copy
Cells.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Range(sSelection).Select
End Function

HTH/

"Steve B" wrote:

I have a template which draws values from formulas that reference other
workbooks. Is there a way, on save, to convert all formulas to values so the
new workbook is a 'snapshot' that can be distributed without needing the
reference to the linked files?

TIA, Steve

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Convert formulas to values on save

The only problem I have with copying to the template file and doing a
Save-As is that the code stays with the workbook unless you use code to
remove all the code.

Copying to a new workbook creates a code-free workbook.

--
steveB

Remove "AYN" from email to respond
"quartz" wrote in message
...
One way:

Copy the following sub into the "ThisWorkbook" module (NOTE: edit the
sheet
name appropriately):

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Call ReplaceFormulasWithValues("Sheet1") '<change to your sheet name
End Sub

Then copy the following function into a normal module:

Public Function ReplaceFormulasWithValues(argSheetName As String)
'REPLACE SHEET CONTENTS WITH VALUES
Dim sSelection As String
Sheets(argSheetName).Activate
sSelection = Selection.Address
Cells.Copy
Cells.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Range(sSelection).Select
End Function

HTH/

"Steve B" wrote:

I have a template which draws values from formulas that reference other
workbooks. Is there a way, on save, to convert all formulas to values so
the
new workbook is a 'snapshot' that can be distributed without needing the
reference to the linked files?

TIA, Steve



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Convert formulas to values on save

Hi Steve,

That is a good point, it depends on what effect the OP is after, does the OP
want the code to work on distributed files? - I have some that do and some
that don't. In any case, between the two of us we've covered both bases...

"STEVE BELL" wrote:

The only problem I have with copying to the template file and doing a
Save-As is that the code stays with the workbook unless you use code to
remove all the code.

Copying to a new workbook creates a code-free workbook.

--
steveB

Remove "AYN" from email to respond
"quartz" wrote in message
...
One way:

Copy the following sub into the "ThisWorkbook" module (NOTE: edit the
sheet
name appropriately):

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Call ReplaceFormulasWithValues("Sheet1") '<change to your sheet name
End Sub

Then copy the following function into a normal module:

Public Function ReplaceFormulasWithValues(argSheetName As String)
'REPLACE SHEET CONTENTS WITH VALUES
Dim sSelection As String
Sheets(argSheetName).Activate
sSelection = Selection.Address
Cells.Copy
Cells.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Range(sSelection).Select
End Function

HTH/

"Steve B" wrote:

I have a template which draws values from formulas that reference other
workbooks. Is there a way, on save, to convert all formulas to values so
the
new workbook is a 'snapshot' that can be distributed without needing the
reference to the linked files?

TIA, Steve






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Convert formulas to values on save

Quartz,

Thanks for the kind words!

As always it is not a matter of if, but a matter of what you want...

The hardest issue I have is getting my clients to be very specific about
what they want - And never ask If...

--
steveB

Remove "AYN" from email to respond
"quartz" wrote in message
...
Hi Steve,

That is a good point, it depends on what effect the OP is after, does the
OP
want the code to work on distributed files? - I have some that do and some
that don't. In any case, between the two of us we've covered both bases...

"STEVE BELL" wrote:

The only problem I have with copying to the template file and doing a
Save-As is that the code stays with the workbook unless you use code to
remove all the code.

Copying to a new workbook creates a code-free workbook.

--
steveB

Remove "AYN" from email to respond
"quartz" wrote in message
...
One way:

Copy the following sub into the "ThisWorkbook" module (NOTE: edit the
sheet
name appropriately):

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Call ReplaceFormulasWithValues("Sheet1") '<change to your sheet name
End Sub

Then copy the following function into a normal module:

Public Function ReplaceFormulasWithValues(argSheetName As String)
'REPLACE SHEET CONTENTS WITH VALUES
Dim sSelection As String
Sheets(argSheetName).Activate
sSelection = Selection.Address
Cells.Copy
Cells.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Range(sSelection).Select
End Function

HTH/

"Steve B" wrote:

I have a template which draws values from formulas that reference
other
workbooks. Is there a way, on save, to convert all formulas to values
so
the
new workbook is a 'snapshot' that can be distributed without needing
the
reference to the linked files?

TIA, Steve






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
Save Workbook but without Formulas (just values) sdg8481 Excel Discussion (Misc queries) 1 March 11th 07 03:48 PM
convert formulas to values MatthewFlinchem Excel Worksheet Functions 3 May 17th 06 04:39 PM
Easily convert all formulas in 3d spreadsheet to values? Jazza Excel Worksheet Functions 2 April 9th 06 04:46 AM
Convert Values to formulas TSter Excel Worksheet Functions 4 January 15th 06 09:26 PM
Convert Formulas to Values and Preserve Formatting Tenacity Excel Discussion (Misc queries) 2 August 12th 05 01:00 AM


All times are GMT +1. The time now is 06:50 PM.

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"