Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 10th, 2005, 07:06 AM
Registered User
 
Join Date: Jun 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel VB Automation

 Hi,

 I am trying to open a workbook from a VB program and get
 the work book to calculate (calculation takes 7 mins so the user wants the workbook to be updated by a program and for the user not to have to endure this wait:

      oXlApp.SendKeys "%^{F9}"

  This line of code works when the workbook is opened by human but not when opened by the program. Cells containing formulas end up
 #NAME? in this case. The spreadsheet was written by another user - so the formulas are not in my domain.

Any help much appreciated. Have searched thru my copy of Excel 2002 VBA - but was not able to find anything to solve my problem.

thanks
jeannief

 
Old June 10th, 2005, 07:15 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you should allow the automation to force a calculate on the workbook.
oXlApp.Calculate
this should force a recalculation of the whole excel application.

alternatively...
oxlapp.Worksheets(1).Calculate
should calculate a specific worksheet in a specific workbook

cheers

Matt

 
Old June 10th, 2005, 07:47 AM
Registered User
 
Join Date: Jun 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Matt,

Thanks for the response. However, i had already tried these approaches without success.

Set oXlApp = CreateObject("Excel.Application")
    oXlApp.Visible = False

    Set wb = oXlApp.Workbooks.Open(sFileName)
    oXlApp.Calculation = xlCalculationManual

    'oXlApp.ScreenUpdating = True
    'oXlApp.Visible = True

    sNow = Format(Now(), "dd-mmm-yy hh:mm:ss")
    oXlApp.Worksheets("Menu").Range("rSelectedTime").V alue = sNow

    oXlApp.SendKeys "%^{F9}" '1
    oXlApp.Calculate '2
    For Each Sheet In oXlApp.Worksheets '3
        Sheet.Calculate
    Next

Additionally, I had put the code in the workbook itself and used the VB program to set a "flag" in a cell, so that the workbook_open method would check the flag and then execute the recalculation. Once again, when the workbook is opened manually the method executes and the workbook updates, but when opened by the vb program the function executes but the calculation results in formula cells with #NAME?

thanks again.

j

 
Old June 14th, 2005, 06:06 AM
Registered User
 
Join Date: Jun 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default


For the benefit of others who may have the same problem:

The issue was that the functions used in the workbook were in an addin xll. It seems that these do not load when a workbook is opened using automation. It is necessary to open a blank workbook, remove and re-add the addin. (the addin is checked but not loaded by default)

    oXlApp.Workbooks.Add
    oXlApp.Visible = False
    Set oAddin = oXlApp.AddIns.Add("your addin .xll path ", True)
    oAddin.Installed = False
    DoEvents
    oXlApp.AddIns.Add "your addin .xll path" , True
    oAddin.Installed = True

    Set wb = oXlApp.Workbooks.Open(sFileName)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Pictures in Automation of Excel gardengirl447 BOOK: Access 2003 VBA Programmer's Reference 2 July 4th, 2011 06:54 PM
Excel Automation MAKO C# 0 August 16th, 2006 01:05 PM
Automation with Access and Excel venomm Access 2 March 20th, 2005 11:34 AM
Excel Automation ameysun C# 0 November 4th, 2004 07:33 AM
Excel Automation ameysun Pro VB 6 0 November 4th, 2004 02:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.