Excel Automation - Running an Excel Macro or Function
SHardy
Member Posts: 38
Version 3.70.B
Hi,
I am using Excel automation and, while the workbook is open, I am wanting to run a macro. I have setup a very simple "Hello World" message macro to test with. I have entered the following line of code to run the macro:
XlApplication.Run('HelloWorld');
However, Navision returns the following error:
"The call to member Run failed. Microsoft Office Excel returned the following message: The macro 'HelloWorld' cannot be found."
Help!!! Why might this be?
Once I have successfully got this working, I then want to change it to run a function that requires a string to be passed to it and that will then return an integer. Any help with this would be appreciated. The code in Excel is as follows:
Function ReturnCellLength(CellRef As String) As Integer
On Error Resume Next
ReturnCellLength = 0
ReturnCellLength = Len(Range(CellRef).Value)
End Function
How would I call this function passing a cell reference as a string (e.g. "A1")?
Note: Both of these macros are within the "ThisWorkbook" module.
Thanks,
Simon
Hi,
I am using Excel automation and, while the workbook is open, I am wanting to run a macro. I have setup a very simple "Hello World" message macro to test with. I have entered the following line of code to run the macro:
XlApplication.Run('HelloWorld');
However, Navision returns the following error:
"The call to member Run failed. Microsoft Office Excel returned the following message: The macro 'HelloWorld' cannot be found."
Help!!! Why might this be?
Once I have successfully got this working, I then want to change it to run a function that requires a string to be passed to it and that will then return an integer. Any help with this would be appreciated. The code in Excel is as follows:
Function ReturnCellLength(CellRef As String) As Integer
On Error Resume Next
ReturnCellLength = 0
ReturnCellLength = Len(Range(CellRef).Value)
End Function
How would I call this function passing a cell reference as a string (e.g. "A1")?
Note: Both of these macros are within the "ThisWorkbook" module.
Thanks,
Simon
Navision Version(s):
Server - 3.70.B
Client - 3.60
Server - 3.70.B
Client - 3.60
0
Comments
-
I think the macro should be in either the personal modules or in the excel template (if you use any)0
-
Aha! That solved it. Something so simple, but not so obvious.
I have moved the macros onto a new module and all works fine.
Thanks.Navision Version(s):
Server - 3.70.B
Client - 3.600
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 322 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
