Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default call a excel function from a vb project

Hi,

I have written an excel addin that builds reports on a workbook when the
user clicks on a customized toolbar button (that calls a macro). In
addition to that, I also need to be able to run that macro automatically at
6am every morning through a vb application that would always be running in
the background.

There are two main scenarios that I need to handle in that vb application.
One (the easiest one) is when excel is not running. I have a simple shell
command that calls excel (which loads the addin) and also sends a string with
the argument that runs the macro. In the addin side, upon workbook open,
there is code that reads in the command line, parses it and runs the macro if
the correct argument is sent.
That scenario works well.

The second scenario is when excel is already running. I am getting a
reference of that specific excel object through the GetObject function (so
that I can see the actual instance running instead of creating a new
instance). Through that reference, I can see the whether or not the
specific workbook is loaded, and if it's not, I open it. Now, my obstacle
is when trying to run the macro from the addin... how do I call that macro?


Thank you.

This is the code that I have so far:

strFileName = "C:\Projects\ExcelAddIn\ApiCallTest.xls"
bExcelRunning = ProcessIsRunning("Excel")

If bExcelRunning = False Then
ExcelWasNotRunning = True
RetVal = Shell("C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE
C:\Projects\ExcelAddIn\ApiCallTest.xls /e/RunReport/", 1)
Else
Set appXL = GetObject(, "Excel.Application")

For i = 1 To appXL.Workbooks.Count
If appXL.Workbooks(i).FullName = strFileName Then
bFound = True
Exit For
End If
Next i

If bFound = False Then
'open the workbook
Set objWorkbook = GetObject(strFileName)
bWorkbookWasClosed = True
appXL.Visible = True
appXL.Parent.Windows(1).Visible = True
End If

'***Here I need to call the "RunReport" macro ***


End If

If ExcelWasNotRunning = True Then
appXL.Application.Quit
End If
Set appXL = Nothing

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default call a excel function from a vb project

I am looking for the same answer. If you are able to find the answer to
this, please post it here. Thanks !!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default call a excel function from a vb project

Try

appXL.Run "FileName.xla!SubName"

Tim

"Alex281" wrote in message
...
Hi,

I have written an excel addin that builds reports on a workbook when the
user clicks on a customized toolbar button (that calls a macro). In
addition to that, I also need to be able to run that macro automatically
at
6am every morning through a vb application that would always be running in
the background.

There are two main scenarios that I need to handle in that vb application.
One (the easiest one) is when excel is not running. I have a simple shell
command that calls excel (which loads the addin) and also sends a string
with
the argument that runs the macro. In the addin side, upon workbook open,
there is code that reads in the command line, parses it and runs the macro
if
the correct argument is sent.
That scenario works well.

The second scenario is when excel is already running. I am getting a
reference of that specific excel object through the GetObject function (so
that I can see the actual instance running instead of creating a new
instance). Through that reference, I can see the whether or not the
specific workbook is loaded, and if it's not, I open it. Now, my
obstacle
is when trying to run the macro from the addin... how do I call that
macro?


Thank you.

This is the code that I have so far:

strFileName = "C:\Projects\ExcelAddIn\ApiCallTest.xls"
bExcelRunning = ProcessIsRunning("Excel")

If bExcelRunning = False Then
ExcelWasNotRunning = True
RetVal = Shell("C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE
C:\Projects\ExcelAddIn\ApiCallTest.xls /e/RunReport/", 1)
Else
Set appXL = GetObject(, "Excel.Application")

For i = 1 To appXL.Workbooks.Count
If appXL.Workbooks(i).FullName = strFileName Then
bFound = True
Exit For
End If
Next i

If bFound = False Then
'open the workbook
Set objWorkbook = GetObject(strFileName)
bWorkbookWasClosed = True
appXL.Visible = True
appXL.Parent.Windows(1).Visible = True
End If

'***Here I need to call the "RunReport" macro ***


End If

If ExcelWasNotRunning = True Then
appXL.Application.Quit
End If
Set appXL = Nothing

End Sub



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
Is it possible to call an excel function indirectly? Alban??? Excel Discussion (Misc queries) 4 February 27th 09 04:59 PM
CALL .NET FUNCTION FROM EXCEL VSTO Beginner Excel Worksheet Functions 0 February 27th 08 06:57 AM
Referencing Call to Another Project Phil B[_2_] Excel Programming 4 August 1st 05 03:52 AM
Call a add_in function in excel vba? libing Excel Programming 6 June 14th 05 05:15 AM
Help with VB Call function from Excel Lawrence M. Seldin, CMC, CPC Excel Programming 0 June 3rd 05 06:13 PM


All times are GMT +1. The time now is 07:20 AM.

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"