Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Execute Excel2000, which has an add-in, from Access2000's VBA


Message #1 by "Bill Paen" <bill.paen@b...> on Sun, 22 Sep 2002 22:48:33
 
Question: How can I open an Excel file from Access 2000 without having to
          open the Excel Application before-hand?

Problem: If I want to open an Excel file named "BPA.xls", please see the
         code below, from an Access2000's cutomized menu written in VBA, I
         have to open the Excel Application first so that the "BPA.xls"
         can then be opened by the Access2000. Otherwise, Access gives me
         a "Action Failed" dialog box with the following value:

Macro Name: RunGasContract
Condition: True
Action Name: RunCode
Arguments: RunGasContracts()

Application Design: 
 
On the Menu Bar, there is a customized menu called "Gas Contract", once clicked on, it displays a macro called "RunGasContract".
This macro will execute the following code in VBA.

Application Code:

Module Name: RunGasContract
Function RunGasContracts()
    Dim appExcel As Excel.Application, strxls As String      
    Set appExcel = GetObject(, "Excel.Application")    
    appExcel.Visible = True
    strxls = ".........BPA.xls"    
    appExcel.Workbooks.Open (strxls)
    Set appExcel = Nothing
End Function


That's all and thanks in advance for helping me.

Bill. 



 

 
Message #2 by "Bob Bedell" <bobbedell15@m...> on Sun, 22 Sep 2002 23:05:12 +0000
Hi Bill,

The line Set appExcel = GetObject(, "Excel.Application") checks to see
if an instance of Excel is already running. If an instance isn't
running, you get your error message. Either of the following two
procedures will automate opening an instance of Excel for your workbook
to run in.

Function RunGasContracts()
    Dim appExcel As Object
    ' Specify path for GetObject function
    Set appExcel = GetObject("c:\Temp\BPA.XLS")
    appExcel.Application.Visible = True
    appExcel.Parent.Windows(1).Visible = True
    Set appExcel = Nothing
End Function

(Using the CreateObject function)

Function RunGasContracts()
    Dim appExcel As Excel.Application, strxls As String
    Set appExcel = CreateObject("Excel.Application")
    appExcel.Visible = True
    strxls = "C:\Temp\BPA.xls"
    appExcel.Workbooks.Open (strxls)
    Set appExcel = Nothing
End Function

Best,

Bob

>From: "Bill Paen" <bill.paen@b...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] Execute Excel2000, which has an add-in, from Access2000's 
>VBA
>Date: Sun, 22 Sep 2002 22:48:33
>
>Question: How can I open an Excel file from Access 2000 without having to
>           open the Excel Application before-hand?
>
>Problem: If I want to open an Excel file named "BPA.xls", please see the
>          code below, from an Access2000's cutomized menu written in VBA, I
>          have to open the Excel Application first so that the "BPA.xls"
>          can then be opened by the Access2000. Otherwise, Access gives me
>          a "Action Failed" dialog box with the following value:
>
>Macro Name: RunGasContract
>Condition: True
>Action Name: RunCode
>Arguments: RunGasContracts()
>
>Application Design:
>
>On the Menu Bar, there is a customized menu called "Gas Contract", once 
>clicked on, it displays a macro called "RunGasContract". This macro will 
>execute the following code in VBA.
>
>Application Code:
>
>Module Name: RunGasContract
>Function RunGasContracts()
>     Dim appExcel As Excel.Application, strxls As String
>     Set appExcel = GetObject(, "Excel.Application")
>     appExcel.Visible = True
>     strxls = ".........BPA.xls"
>     appExcel.Workbooks.Open (strxls)
>     Set appExcel = Nothing
>End Function
>
>
>That's all and thanks in advance for helping me.
>
>Bill.
>
>
>
>
>
>






_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com

Message #3 by bill.paen@b... on Mon, 23 Sep 2002 12:34:42 -0600
Thank you for the answer. It really helps and works too. 

Bill. 

-----Original Message-----
From: Bob Bedell [mailto:bobbedell15@m...]
Sent: Sunday, September 22, 2002 5:05 PM
To: Access
Subject: [access] Re: Execute Excel2000, which has an add-in, from
Access2000's VBA


Hi Bill,

The line Set appExcel = GetObject(, "Excel.Application") checks to see
if an instance of Excel is already running. If an instance isn't
running, you get your error message. Either of the following two
procedures will automate opening an instance of Excel for your workbook
to run in.

Function RunGasContracts()
    Dim appExcel As Object
    ' Specify path for GetObject function
    Set appExcel = GetObject("c:\Temp\BPA.XLS")
    appExcel.Application.Visible = True
    appExcel.Parent.Windows(1).Visible = True
    Set appExcel = Nothing
End Function

(Using the CreateObject function)

Function RunGasContracts()
    Dim appExcel As Excel.Application, strxls As String
    Set appExcel = CreateObject("Excel.Application")
    appExcel.Visible = True
    strxls = "C:\Temp\BPA.xls"
    appExcel.Workbooks.Open (strxls)
    Set appExcel = Nothing
End Function

Best,

Bob

>From: "Bill Paen" <bill.paen@b...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] Execute Excel2000, which has an add-in, from Access2000's

>VBA
>Date: Sun, 22 Sep 2002 22:48:33
>
>Question: How can I open an Excel file from Access 2000 without having to
>           open the Excel Application before-hand?
>
>Problem: If I want to open an Excel file named "BPA.xls", please see the
>          code below, from an Access2000's cutomized menu written in VBA, I
>          have to open the Excel Application first so that the "BPA.xls"
>          can then be opened by the Access2000. Otherwise, Access gives me
>          a "Action Failed" dialog box with the following value:
>
>Macro Name: RunGasContract
>Condition: True
>Action Name: RunCode
>Arguments: RunGasContracts()
>
>Application Design:
>
>On the Menu Bar, there is a customized menu called "Gas Contract", once 
>clicked on, it displays a macro called "RunGasContract". This macro will 
>execute the following code in VBA.
>
>Application Code:
>
>Module Name: RunGasContract
>Function RunGasContracts()
>     Dim appExcel As Excel.Application, strxls As String
>     Set appExcel = GetObject(, "Excel.Application")
>     appExcel.Visible = True
>     strxls = ".........BPA.xls"
>     appExcel.Workbooks.Open (strxls)
>     Set appExcel = Nothing
>End Function
>
>
>That's all and thanks in advance for helping me.
>
>Bill.
>
>
>
>
>
>






_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com



  Return to Index