Jose Luis9400
Active Member
- Joined
- Jan 19, 2017
- Messages
- 2
- Thread Author
-
- #1
Hi,
I have a Excel macro that copies a specific cell value. Is posible to execute it from another application without losing the focus?
Thanks in advance.
Regards,
Jose Luis
I have a Excel macro that copies a specific cell value. Is posible to execute it from another application without losing the focus?
Thanks in advance.
Regards,
Jose Luis
Solution
I know you can do this via a VBS file, copy the following and paste into notepad and save with a .vbs extension:
Adjust the workbook location and Function name to your function you wish to execute.
If you need to run this as a command I'm sure you could execute "wscript yourfile.vbs", or perhaps cscript instead.
If you need to do this within your own program you are righting without any external scripting Microsoft...
Code:
Option Explicit
On Error Resume Next
ExcelMacroExample
Sub ExcelMacroExample()
Dim xlApp
Dim xlBook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\temp\Book1.xlsm", 0, True)
xlApp.Run "MyFunction"
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
Adjust the workbook location and Function name to your function you wish to execute.
If you need to run this as a command I'm sure you could execute "wscript yourfile.vbs", or perhaps cscript instead.
If you need to do this within your own program you are righting without any external scripting Microsoft...
- Joined
- Aug 3, 2010
- Messages
- 1,288
I know you can do this via a VBS file, copy the following and paste into notepad and save with a .vbs extension:
Adjust the workbook location and Function name to your function you wish to execute.
If you need to run this as a command I'm sure you could execute "wscript yourfile.vbs", or perhaps cscript instead.
If you need to do this within your own program you are righting without any external scripting Microsoft has extensive support in .NET via the Excel.Application COM interface.
Code:
Option Explicit
On Error Resume Next
ExcelMacroExample
Sub ExcelMacroExample()
Dim xlApp
Dim xlBook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\temp\Book1.xlsm", 0, True)
xlApp.Run "MyFunction"
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
Adjust the workbook location and Function name to your function you wish to execute.
If you need to run this as a command I'm sure you could execute "wscript yourfile.vbs", or perhaps cscript instead.
If you need to do this within your own program you are righting without any external scripting Microsoft has extensive support in .NET via the Excel.Application COM interface.