Publisher and Excel

J

Jean Lancelin

Hi,

I would like to write a web page under publisher 2003, where there is
button which launch a macro in excel on the server, when clicked.
I found that the following code that I have to put:

Dim xls
Set xls = CreateObject("Excel.Application")
xls.Application.Visible = False
xls.Workbooks.Open ExcelFilePath, 3, False
xls.Run("ThisWorkBook.Macro1")
Set xls = Nothing

But I am a newbe and I don't know how to do.

I thank you in advance for your help.
Jean
 
E

Ed Bennett

Jean Lancelin said:
I would like to write a web page under publisher 2003, where there is
button which launch a macro in excel on the server, when clicked.
I found that the following code that I have to put:

Why do you want to run a macro in Excel on the SERVER?

You cannot include VBA code in a web page. It doesn't work.

The code you listed is VBScript I think, and will launch Excel on the
CLIENT.

It might open a workbook and so a macro from the server, but it will run on
the client.

This question might be better asked in the .webdesign group.
 
T

Tan

Ed,

Is there a possibility to open an Excel document in Publisher and
automatically run a certain macro and doing so in a macro?

Thanks!
 
E

Ed Bennett

Tan said:
Is there a possibility to open an Excel document in Publisher and
automatically run a certain macro and doing so in a macro?

I'm not sure what you're asking - you can insert an Excel sheet as an OLE
object, or you can call Excel and use Excel's automation interface to open a
sheet and execute a macro therein.
 
E

Ed Bennett

Tan said:
I would like to call the Excel from Publisher and run a macro that is
in the Excel document. Is that possible?

Probably but you would need to ask some Excel experts, as this relies
entirely on Excel's object model and VBA.

You would need to add a reference to the Microsoft Excel object library, and
use

Dim myExcelApp As New Excel.Application

to call the application. Where you go from there is known as well to you as
it is to me.
 
Z

Zack Barresse

Tan said:
I would like to call the Excel from Publisher and run a macro that is in the
Excel document. Is that possible?

Hi there,

The best way is to make use of Early Binding, as Ed has said, making a
reference (from your VBE | Tools | References) to the "Microsoft Excel xx.0
Object Library", where xx is your version number referencing.* This has the
best benefit (in my humble opinion) of giving you the ability to access
Excel's Intellisense and Object Model (VBE | F2).


To perform the requested task, follow these steps:

From Publisher, hit Alt + F11
Press Ctrl + R to view the Project Explorer (left pane)
Select Document (name in Bold) in Explorer window
Select Insert (menu) | Module
Copy/Paste the following code on right (Code) pane ...

Option Explicit

Sub CallMyExcelMacro()
'Must set a Reference to "Microsoft Excel xx.0 Object Library
' where xx is your Office version (Application | Help)
Dim ExcelApp As New Excel.Application
Dim ExcelFile As Excel.Workbook
'Change path and filename to match desired
' If either is invalid an error will occur
' Error trap if necessary
Set ExcelFile = ExcelApp.Workbooks.Open("C:\Documents and
Settings\Rob\Desktop\Book4.xls")
ExcelApp.Visible = True
'Change Module name and Routine name to match desired
ExcelApp.Run "Module1.Macro1"
'The False means it will not save the Excel file
' Change to True if Saving is required.
ExcelFile.Close False
ExcelApp.Quit
End Sub


HTH

*11.0 is Excel 2003, 10.0 is Excel 2002, etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top