Run a Macro in Excel?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
16-07-15 05:53 PM
Hi everybody,
Sorry if the question is obvious, I am rather new to BluePrism (and not entirely a VBA expert either).
I am trying to make the bot run a macro in an Excel sheet. However, I cannot seem to make the code work. Normally I would just use the Application.Run, but in BluePrism I am told that this function is not defined.
Any help as to how I run a macro once worksheet and macro name have been obtained?
Thank you very much and best regards from sunny Denmark,
Christian
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
16-07-15 06:56 PM
Hi Christian,
I currently have a process in production that runs macros in Excel. I used the Global Send Keys commands to call the macros in Excel since each macro can be assigned a hot-key command.
Hope that helps.
Justin
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
16-07-15 07:03 PM
Hi Justin,
Thank you, that might just work. Could you explain how I obtain the Global Send Keys commands?
I would prefer to run the macro by name however. If anyone has ideas on how to do this, I would be very happy.
All the best,
Christian

Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
16-07-15 07:04 PM
I found a solution to run a query and a Saved Import in MS Access. Perhaps this will help with the Excel problem.
First, I located the dao.dll for Access, downloaded it, and added it to Blue Prism folder. The Excel .dll should be just as available.
C:\Program Files\Blue Prism Limited\Blue Prism Automate
Microsoft.Office.interop.access.dao.dll
Microsoft.Office.Interop.Access.dll
In the comment block of the Initialize page of the MS Access – VBO object, I navigated to the Code Options tab. There I checked/added the DLLs to the External References and added namespaces to the Namespace Imports section.
External References
Microsoft.Office.Interop.Access.dll
Microsoft.Office.interop.access.dao.dll
Namespace Imports
System
System.Collections.Generic
Microsoft.VisualBasic
System.IO
System.Runtime.InteropServices
System.Diagnostics
Microsoft.Office.interop.access.dao
System.Data
System.Data.OLEDB
In the MS ACCESS – vbo object, I created a page (Open Query) with a data item called QueryToOpen, a handle, and a collection to receive the query results.
After checking the instance handle, I crafted a code stage that takes the handle and the QueryToOpen variable and used it in the code section. The code is as follows:
Dim accessDb As Object = GetInstance(handle)
accessDb.DoCmd.OpenQuery(QueryToOpen)
Additionally I created another page (Run Saved Imports) with a code stage that uses this code:
Dim access As Object = GetInstance(handle)
access.DoCmd.RunSavedImportExport(savedImportToRun)
I hope this helps,
Michael Zimmerman
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
16-07-15 07:21 PM
Hi Christian,
At the Object level, use a Navigate stage. The Element will be the top most Element which will be your application. The Action will be ""Global Send Keys"". Your input will be a text command that will look something like ""{CTRL}"". Just replace the ""A"" with your actual hot-key letter assigned in Excel.
Here's a list of commands http://msdn.microsoft.com/en-us/library/aa248599(v=vs.60).aspx.
Have fun!
Justin
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
16-07-15 07:26 PM
Hi Christian,
I almost forgot one important step when using hot keys. When stepping through your process while testing, you MUST play through your send key stage; you cannot step through it. Global Send Key commands require that the application has complete focus. If you step through the send key stage, you are putting the focus back on the BP object page and the hot key will try to run against the BP object, not your application.
I hope that makes sense.
Justin
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
16-07-15 07:41 PM
Hi Justin,
Ah ok. I think that one is called ""Window Press Key"" in my version, hence the confusion. Will work around with it a little bit. I set the shortcut as ""^+{ENTER}"" in Excel, so hopefully that will work :)
Thanks a million for the reply,
Christian
