Reputation: 409
I'm trying to create a ribbon for Office Word 365 with two editboxes and a checkbox.
I have a macro I would like to use that input afterwards.
So far I have used the Ribbon Designer in Visual Studio to create an Add-in ribbon.
The Add-in shows in Word and it looks like it's supposed to. I just can't figure out how to get the input from the editboxes and checkbox to vba.
The VBA code I have looks like this:
Sub PasteAndSelectPicture()
Application.ScreenUpdating = False
Dim ils As Word.InlineShape
Dim shp As Word.Shape
Dim lNrIls As Long
Dim lNrShp As Long
Dim rngDoc As Word.Range
Dim rngSel As Word.Range
Set rngDoc = ActiveDocument.Content
Set rngSel = Selection.Range
rngDoc.End = rngSel.End + 1
'Get an InlineShape
lNrIls = rngDoc.InlineShapes.Count
Selection.PasteSpecial Link:=False, DataType:=wdPasteEnhancedMetafile, Placement:=wdInLine, DisplayAsIcon:=False
Debug.Print rngDoc.InlineShapes.Count, lNrIls
Set ils = rngDoc.InlineShapes(lNrIls + 1)
ils.Width = Application.CentimetersToPoints(VAR1)
Set shp = ils.ConvertToShape
shp.IncrementRotation VAR2
shp.ConvertToInlineShape
Application.ScreenUpdating = True
End Sub
I'd like the VAR1 and VAR2 to be inputs from the two editboxes.
Upvotes: 1
Views: 310
Reputation: 25663
By design, it's not possible to access Ribbon controls from a project that does not contain that Ribbon's XML. While the VSTO Ribbon Designer is "nice to have" you cannot use it with VBA code - only with code in the VSTO project that contains the Ribbon.
That means you either need to write VB.NET code in the VSTO project, or you need to create the Ribbon XML differently.
If you want to use VBA then you need the Ribbon XML (there is an "Export" option in VSTO). Using the Custom UI Editor the Ribbon XML can be incorporated into a Word docm or dotm file.
The information in the series of articles Customizing the 2007 Office Fluent Ribbon for Developers describes how to write VBA code that uses controls in the Ribbon XML. There are also lots of articles, discussions and examples on the Internet, plus a really good book on the subject (RibbonX Customizing the Office 2007 RIbbon).
Upvotes: 2