Skip to content

Commit a33dcb7

Browse files
committed
2 parents 42d216f + 197aae5 commit a33dcb7

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

FSharpRibbon/MyRibbon.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ open Microsoft.Office.Interop.Excel
66
open ExcelDna.Integration
77
open ExcelDna.Integration.CustomUI
88

9-
// This defines a regular Excel macro (in Excel you can press F8, type in the name "showMessage", then click the Run button).
9+
// This defines a regular Excel macro (in Excel you can press Alt + F8, type in the name "showMessage", then click the Run button).
1010
// For the ribbon, it will be run through the ExcelRibbon.RunTagMacro(...) helper, which run whatever macro is specified in the button tag attribute
1111
// One advantage is that you can
1212
[<ExcelCommand>]
@@ -21,7 +21,7 @@ type public MyRibbon() =
2121
inherit ExcelRibbon()
2222

2323
// The ribbon xml definition could also be placed in the .dna file
24-
// Remeber to switch on the ExcelOption "Show add-in user interface errors" option (under the Advanced tab under General)
24+
// Remember to switch on the ExcelOption "Show add-in user interface errors" option (under the Advanced tab under General)
2525
override this.GetCustomUI(ribbonId) =
2626
@"<customUI xmlns='http://schemas.microsoft.com/office/2006/01/customui' >
2727
<ribbon>
@@ -47,4 +47,4 @@ type public MyRibbon() =
4747
cellA1.Value2 <- app.Version
4848
// could also replace the last line with
4949
// cellA1.Value(XlRangeValueDataType.xlRangeValueDefault) <- app.Version
50-
// but Range.Value is an indexer property, so it's a bit inconvenient
50+
// but Range.Value is an indexer property, so it's a bit inconvenient

FSharpRibbon/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ The interesting code is in MyRibbon.fs
1010
* Copy the test code into Library1.fs
1111
* F5 to run and check that the funciton works in Excel
1212
* Add new file with the code in MyRibbon.fs
13+
* Add a reference to System.Windows.Forms.dll
14+
* Install-Package Excel-DNA.Interop
1315
* F5 to run and check that the ribbon is there and the buttons work
1416

1517
## Using the COM object model

Misc/ComObjectModel.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Shows how to get hold of the Excel COM Application object
2+
3+
// Install the 'ExcelDna.Interop' package from NuGet, or reference the two assemblies:
4+
// * Microsoft.Office.Interop.Excel.dll
5+
// * Office.dll
6+
7+
using ExcelDna.Integration;
8+
using Microsoft.Office.Interop.Excel;
9+
10+
public class TestCommands
11+
{
12+
// Defines a macro that uses the COM object model to add a diamond shape to the active sheet.
13+
[ExcelCommand(ShortCut = "^D")] // Ctrl+Shift+D
14+
public static void AddDiamond()
15+
{
16+
Application xlApp = (Application)ExcelDnaUtil.Application;
17+
string version = xlApp.Version;
18+
19+
Worksheet ws = xlApp.ActiveSheet as Worksheet; // Need to change type - it might be a Chart, then ws would be null
20+
Shape diamond = ws.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeDiamond, 10, 10, 100, 100);
21+
diamond.Fill.BackColor.RGB = (int)XlRgbColor.rgbSlateBlue;
22+
}
23+
}

0 commit comments

Comments
 (0)