PC Review


Reply
Thread Tools Rate Thread

Calculate Sheet Option

 
 
=?Utf-8?B?VGVycnkgSG9sbGFuZA==?=
Guest
Posts: n/a
 
      7th Mar 2007
I have a vb app that programmatically creates an Excel template based on data
in a couple of other excel worksheets.

The main function that creates this template is posted below. In this you
will see that I have the following

objWBROI - New workbook that I am creating3
objWSCostCentres - Existing worksheet that I pull some data from to crate
new workbook
objWSTemplate - Second worksheet that I use to create new workbook

The following loop is where i add copies of objWSTemplate to my new workbook

For intCostCentre = 2 To intCostCentres
SetBudgetFigures objWSCostCentres, objWSTemplate, intCostCentre
objWSTemplate.Copy after:=objWBROI.Sheets(objWBROI.Sheets.Count)
objWBROI.ActiveSheet.Name = objWSCostCentres.Cells(RI_COSTCENTREROW,
1 + intCostCentre)
Next

My problem is that, even though objWSTemplate has the Calculate Worksheet
Automatically set, all copies of this sheet in the new workbook have this
option set to Manual. How do I overcome this?




Public Function CreateTemplate(intYear As Integer)

Const RI_COSTCENTREROW = 3

Dim objWBCostCentreBudgets As Excel.Workbook 'Workbook that contains
cost centre budgets
Dim objWSCostCentres As Excel.Worksheet 'Worksheet that contains
list of cost centres and their budgets
Dim objWSTemplate As Excel.Worksheet 'Worksheets that
contains ROI template

Dim objWBROI As Excel.Workbook 'New ROI workbook that
is generated from list of cost centre budgets

Dim intCostCentres As Integer
Dim intCostCentre As Integer

m_intYear = intYear

m_udtProps.strTemplatePath = GetYearTemplateDirectory & "\" & DEF_ROI
'TEMPLATE
m_udtProps.strBudgetLookupPath = GetYearTemplateDirectory & "\" &
DEF_COSTCENTREBUDGETS

Set objWBCostCentreBudgets = OpenCostCentreBudgets

Set objWBROI = m_objExcelApp.Workbooks.Add(GetYearTemplateDirectory &
"\" & DEF_ROITEMPLATE) 'new workbook for all cost-centre roi templates

'based on roi.xlt

Set objWSCostCentres = objWBCostCentreBudgets.Sheets("CostCentres")
'List of cost centres
Set objWSTemplate = objWBROI.Sheets("CostCentreTemplate")
'ROI Template

m_objExcelApp.ScreenUpdating = False

'Get number of cost centres in list
intCostCentres = objWSCostCentres.Cells(1,
objWSCostCentres.Columns.Count).End(xlToLeft).Column - 1

For intCostCentre = 2 To intCostCentres
SetBudgetFigures objWSCostCentres, objWSTemplate, intCostCentre
objWSTemplate.Copy after:=objWBROI.Sheets(objWBROI.Sheets.Count)
objWBROI.ActiveSheet.Name = objWSCostCentres.Cells(RI_COSTCENTREROW,
1 + intCostCentre)
Next

'Hide template sheets
objWBROI.Worksheets(SHEET_CONTESTDATA).Visible = False
objWBROI.Worksheets(SHEET_COSTCENTRETEMPLATE).Visible = False

m_objExcelApp.ScreenUpdating = True

'objWBROI.SaveAs GetDirectoryName & "\" & DEF_ROI
objWBROI.SaveAs GetYearTemplateDirectory & "\" & DEF_ROI

'Tidy up
objWBROI.Close
objWBCostCentreBudgets.Close
Set objWSCostCentres = Nothing
Set objWBCostCentreBudgets = Nothing

End Function


 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      7th Mar 2007
Are you writing about .enablecalculation or you writing about the
application.calculation status.

If you're writing about the first, then change the template--or change the
setting after you create the new worksheet.

If you're writing about the second, then this is an application setting--it's
picked up by the first workbook you open in that session. But you can always
change it to automatic.

Or am I just missing the point (it's happened before!).

Terry Holland wrote:
>
> I have a vb app that programmatically creates an Excel template based on data
> in a couple of other excel worksheets.
>
> The main function that creates this template is posted below. In this you
> will see that I have the following
>
> objWBROI - New workbook that I am creating3
> objWSCostCentres - Existing worksheet that I pull some data from to crate
> new workbook
> objWSTemplate - Second worksheet that I use to create new workbook
>
> The following loop is where i add copies of objWSTemplate to my new workbook
>
> For intCostCentre = 2 To intCostCentres
> SetBudgetFigures objWSCostCentres, objWSTemplate, intCostCentre
> objWSTemplate.Copy after:=objWBROI.Sheets(objWBROI.Sheets.Count)
> objWBROI.ActiveSheet.Name = objWSCostCentres.Cells(RI_COSTCENTREROW,
> 1 + intCostCentre)
> Next
>
> My problem is that, even though objWSTemplate has the Calculate Worksheet
> Automatically set, all copies of this sheet in the new workbook have this
> option set to Manual. How do I overcome this?
>
> Public Function CreateTemplate(intYear As Integer)
>
> Const RI_COSTCENTREROW = 3
>
> Dim objWBCostCentreBudgets As Excel.Workbook 'Workbook that contains
> cost centre budgets
> Dim objWSCostCentres As Excel.Worksheet 'Worksheet that contains
> list of cost centres and their budgets
> Dim objWSTemplate As Excel.Worksheet 'Worksheets that
> contains ROI template
>
> Dim objWBROI As Excel.Workbook 'New ROI workbook that
> is generated from list of cost centre budgets
>
> Dim intCostCentres As Integer
> Dim intCostCentre As Integer
>
> m_intYear = intYear
>
> m_udtProps.strTemplatePath = GetYearTemplateDirectory & "\" & DEF_ROI
> 'TEMPLATE
> m_udtProps.strBudgetLookupPath = GetYearTemplateDirectory & "\" &
> DEF_COSTCENTREBUDGETS
>
> Set objWBCostCentreBudgets = OpenCostCentreBudgets
>
> Set objWBROI = m_objExcelApp.Workbooks.Add(GetYearTemplateDirectory &
> "\" & DEF_ROITEMPLATE) 'new workbook for all cost-centre roi templates
>
> 'based on roi.xlt
>
> Set objWSCostCentres = objWBCostCentreBudgets.Sheets("CostCentres")
> 'List of cost centres
> Set objWSTemplate = objWBROI.Sheets("CostCentreTemplate")
> 'ROI Template
>
> m_objExcelApp.ScreenUpdating = False
>
> 'Get number of cost centres in list
> intCostCentres = objWSCostCentres.Cells(1,
> objWSCostCentres.Columns.Count).End(xlToLeft).Column - 1
>
> For intCostCentre = 2 To intCostCentres
> SetBudgetFigures objWSCostCentres, objWSTemplate, intCostCentre
> objWSTemplate.Copy after:=objWBROI.Sheets(objWBROI.Sheets.Count)
> objWBROI.ActiveSheet.Name = objWSCostCentres.Cells(RI_COSTCENTREROW,
> 1 + intCostCentre)
> Next
>
> 'Hide template sheets
> objWBROI.Worksheets(SHEET_CONTESTDATA).Visible = False
> objWBROI.Worksheets(SHEET_COSTCENTRETEMPLATE).Visible = False
>
> m_objExcelApp.ScreenUpdating = True
>
> 'objWBROI.SaveAs GetDirectoryName & "\" & DEF_ROI
> objWBROI.SaveAs GetYearTemplateDirectory & "\" & DEF_ROI
>
> 'Tidy up
> objWBROI.Close
> objWBCostCentreBudgets.Close
> Set objWSCostCentres = Nothing
> Set objWBCostCentreBudgets = Nothing
>
> End Function


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?VGVycnkgSG9sbGFuZA==?=
Guest
Posts: n/a
 
      7th Mar 2007
> If you're writing about the second, then this is an application setting--it's
> picked up by the first workbook you open in that session. But you can always
> change it to automatic.


This is axactly what I needed to change - thanks
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to calculate % in summary sheet from cell A9 in multiple sheet wissam Microsoft Excel Programming 3 25th Jan 2010 03:01 AM
How to calculate % in summary sheet from cell A9 in multiple sheet wissam Microsoft Excel Programming 0 23rd Jan 2010 03:51 AM
Sheet change or sheet calculate? =?Utf-8?B?Q2hlZXRhaGtl?= Microsoft Excel Programming 0 4th Nov 2007 02:37 PM
have calculations from sheet one calculate in table on sheet two =?Utf-8?B?ZWFybA==?= Microsoft Excel Programming 1 29th Aug 2007 08:00 PM
Calculate active sheet on sheet selection a94andwi Microsoft Excel Programming 1 26th Sep 2005 05:23 PM


Features
 

Advertising
 

Newsgroups
 


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