OnAction with parameters - vba

This is my first ever question on SO even I come here regularly (I've always find my answer without having to ask until today). I know this question I've already posted but for some reason i doesn't work for me.
I'm trying to get a right click submenu with a list of every numbered items in my word document. The purpose of it is to insert in a click the numbered and the content text of my numbered item in my document.
The problem is I don't know how to affect each .OnAction (to insert the numbered item in my document) and each .Caption (to show the number and content text of my numbered item in my menu) with a different variable (one for each numbered item). There is probably a problem with my quotes but I cannot see any other solution.
My code is the following :
Option Explicit
Sub ControlButtonNumberedItems()
'Parameters for NumberedItems
Dim i As Integer
i = 1
Dim NumberedItems As Integer
NumberedItems = ActiveDocument.CountNumberedItems
'Parameters for CommanBar
Dim MenuButton As CommandBar
Set MenuButton = Application.CommandBars("Text")
Dim SubMenuButton As CommandBarControl
Set SubMenuButton = MenuButton.Controls.Add(Type:=msoControlPopup, Before:=1)
With SubMenuButton
.Caption = "NumberedItems"
.Tag = "My_Tag"
While i <= NumberedItems
With .Controls.Add(Type:=msoControlButton)
.OnAction = "'InsertNumberedItem""i""'"
.FaceId = 38
.Caption = "MyCaption"
End With
i = i + 1
Wend
End With
End Sub
Sub InsertEvidence(i As Integer)
'Insert NumberRelativeContext
Selection.InsertCrossReference ReferenceType:=wdRefTypeNumberedItem, _
ReferenceKind:=wdNumberRelativeContext, _
ReferenceItem:=i, _
InsertAsHyperlink:=True, _
SeparatorString:=" "
Selection.TypeText Text:=" "
'Insert ContentText
Selection.InsertCrossReference ReferenceType:=wdRefTypeNumberedItem, _
ReferenceKind:=wdContentText, _
ReferenceItem:=i, _
InsertAsHyperlink:=True, _
SeparatorString:=" "
'Text form
Selection.Expand Unit:=wdLine
Selection.Font.Bold = wdToggle
Selection.Font.Italic = wdToggle
Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
Selection.ParagraphFormat.SpaceBefore = 6
End Sub
Sub ResetRightClick()
Application.CommandBars("Text").Reset
End Sub
Thank you in advance for any help. Please let me know if you need any other information.

I didn't know that Word VBA is different from Excel: see the accepted answer here:
VBA Pass arguments with .onAction
This worked for me (just the code needed to show how parameters can be passed):
Sub ControlButtonNumberedItems()
Dim i As Integer
Dim NumberedItems As Integer
'Parameters for CommanBar
Dim MenuButton As CommandBar
Set MenuButton = Application.CommandBars("Text")
Dim SubMenuButton As CommandBarControl
Set SubMenuButton = MenuButton.Controls.Add(Type:=msoControlPopup, Before:=1)
With SubMenuButton
.Caption = "NumberedItems"
.Tag = "My_Tag"
For i = 1 To 5
With .Controls.Add(Type:=msoControlButton)
.OnAction = "InsertNumberedItem"
.FaceId = 38
.Parameter = i
.Caption = "MyCaption " & i
End With
Next i
End With
End Sub
Public Sub InsertNumberedItem()
MsgBox "got " & CommandBars.ActionControl.Parameter
End Sub
Sub ResetRightClick()
Application.CommandBars("Text").Reset
End Sub

Related

MS Word VBA attaching a text box to even and odd header

I have created this code to get my text box in the odd and even headers, but the text box is always attached to the body of the document instead of being in the header.
Dim ndx As Integer
Dim line As String
Dim lineChar As Integer
Dim pages As Integer
Dim Box As Shape
'Since the odd/even headers are different, we need to set them twice
For ndx = 1 To 2 'put back to 1 to 2
If (ActiveDocument.ActiveWindow.Panes(1).pages.Count >= ndx) Then
Selection.GoTo wdGoToPage, wdGoToAbsolute, ndx
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Set HeaderRange = ActiveDocument.Sections.Item(1).Headers(wdHeaderFooterEvenPages).Range
HeaderRange.Text = " "
If ndx = 1 Then
Set Box = ActiveDocument.Shapes.AddTextbox( _
Orientation:=msoTextOrientationHorizontal, _
Left:=InchesToPoints(1), Top:=InchesToPoints(0.5), Width:=InchesToPoints(4.8), Height:=InchesToPoints(0.37))
Else
Set Box = ActiveDocument.Shapes.AddTextbox( _
Orientation:=msoTextOrientationHorizontal, _
Left:=300, Top:=50, Width:=500, Height:=20)
End If
Box.TextFrame.TextRange.Bold = True
Box.TextFrame.TextRange.Font.Size = 8
Box.TextFrame.TextRange.Text = "This is a sample policy from another school district. Contents do not necessarily reflect official " & _
vbCrLf & "MSBA policy, represent MSBA legal advice or service, and are not intended for exact replication."
End If
Next ndx
Thank you for your help.
Your code isn't working because it adds the text box to the document [ActiveDocument.Shapes.AddTextbox] instead of the header. The code below works for me.
Sub TextBoxInHeader()
Dim Box As Shape
Dim ndx As Integer
For ndx = 1 To 3 Step 2
With ActiveDocument.Sections(1).Headers(ndx)
.Range.Text = " "
If ndx = 1 Then 'Primary (odd pages) header
Set Box = .Shapes.AddTextbox( _
Orientation:=msoTextOrientationHorizontal, _
Left:=InchesToPoints(1), Top:=InchesToPoints(0.5), Width:=InchesToPoints(4.8), Height:=InchesToPoints(0.37))
Else 'Even pages header
Set Box = .Shapes.AddTextbox( _
Orientation:=msoTextOrientationHorizontal, _
Left:=300, Top:=50, Width:=500, Height:=20)
End If
End With
With Box.TextFrame.TextRange
.Bold = True
.Font.Size = 8
.Text = "This is a sample policy from another school district. Contents do not necessarily reflect official " & _
vbCrLf & "MSBA policy, represent MSBA legal advice or service, and are not intended for exact replication."
End With
Next ndx
End Sub

VBA coding in Word 2013

I am having an issue regarding VBA in Word 2013. I have limited experience with coding, and macros are a bit of new territory for me.
I have a successful VBA code from a worker that no longer works in my office, and this code allows for a drop down menu in the office forms, allowing the user to choose their location and the footer changes the text address of the office in a string.
What I have been trying to do is to tweak this code so that on choosing the location, instead of showing text at the bottom of the page, the header template will change. I have successfully recorded the macros so it will do what I want on my computer, but when I try to share it with others, a few things happen. The drop down menu doesn't appear, then I have to put in the Developer tab. After that I have to unlock the document each time I want to run the macro (the old documents did not require this even though the old documents are also locked), then I get the error code saying the requested member does not exist, pointing to my recorded macro.
I'm sure I am doing something wrong but I'm unsure what that is. Some help would be greatly appreciated.
Option Explicit
Sub AutoNew()
Dim Mybar As CommandBar
Dim myControl As CommandBarComboBox
Dim cmd As CommandBar
Dim cmdyes As Integer
cmdyes = 0
For Each cmd In CommandBars
If cmd.Name = "Select Location" Then
cmdyes = 1
Exit For
Else
End If
Next
If cmdyes = 1 Then
CommandBars("Select Location").Visible = True
Else
Set Mybar = CommandBars _
.Add(Name:="Select Location", Position:=msoBarFloating, _
Temporary:=False)
Set myControl = CommandBars("Select Location").Controls _
.Add(Type:=msoControlDropdown, Before:=1)
With myControl
.AddItem " South Portland"
.AddItem " Bangor"
.AddItem " Presque Isle"
.ListIndex = 1
.Caption = "Select Office Location"
.Style = msoComboLabel
.BeginGroup = True
.OnAction = "processSelection"
.Tag = "AddresSelect"
End With
End If
CommandBars("Select Location").Visible = True
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields = False Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="password"
' ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:=""
End If
End Sub
Sub AutoOpen()
Dim Mybar As CommandBar
Dim myControl As CommandBarComboBox
Dim cmd As CommandBar
Dim cmdyes As Integer
cmdyes = 0
For Each cmd In CommandBars
If cmd.Name = "Select Location" Then
cmdyes = 1
Exit For
Else
End If
Next
If cmdyes = 1 Then
CommandBars("Select Location").Visible = True
Else
Set Mybar = CommandBars _
.Add(Name:="Select Location", Position:=msoBarFloating, _
Temporary:=False)
Set myControl = CommandBars("Select Location").Controls _
.Add(Type:=msoControlDropdown, Before:=1)
With myControl
.AddItem " South Portland"
.AddItem " Bangor"
.AddItem " Presque Isle"
.ListIndex = 1
.Caption = "Select Office Location"
.Style = msoComboLabel
.BeginGroup = True
.OnAction = "processSelection"
.Tag = "AddresSelect"
End With
End If
CommandBars("Select Location").Visible = True
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields = False Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="password"
' ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:=""
End If
End Sub
Sub processSelection()
Dim userChoice As Long
userChoice = CommandBars("Select Location").Controls(1).ListIndex
Select Case userChoice
Case 1
Call SoPortlandAddress
Case 2
Call BangorAddress
Case Else
Call PresqueIsleAddress
End Select
End Sub
Sub SoPortlandAddress()
'
' SoPortlandAddress Macro
'
'
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Templates.LoadBuildingBlocks
Application.Templates( _
"C:\Users\bex172\AppData\Roaming\Microsoft\Document Building
Blocks\1033\15\Building Blocks.dotx" _
).BuildingBlockEntries("South Portland Header").Insert Where:=Selection.
_
Range, RichText:=True
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect Password:="password"
End If
If ActiveDocument.ProtectionType = wdNoProtection Then
FormLock
End If
End Sub
Sub BangorAddress()
'
' BangorAddress Macro
'
'
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Templates.LoadBuildingBlocks
Application.Templates( _
"C:\Users\bex172\AppData\Roaming\Microsoft\Document Building
Blocks\1033\15\Building Blocks.dotx" _
).BuildingBlockEntries("Bangor Header").Insert Where:=Selection.Range, _
RichText:=True
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect Password:="password"
End If
If ActiveDocument.ProtectionType = wdNoProtection Then
FormLock
End If
End Sub
Sub PresqueIsleAddress()
'
' PresqueIsleAddress Macro
'
'
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Templates.LoadBuildingBlocks
Application.Templates( _
"C:\Users\bex172\AppData\Roaming\Microsoft\Document Building
Blocks\1033\15\Building Blocks.dotx" _
).BuildingBlockEntries("Presque Isle Header").Insert Where:=Selection. _
Range, RichText:=True
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect Password:="password"
End If
If ActiveDocument.ProtectionType = wdNoProtection Then
FormLock
End If
End Sub
Sub FormLock()
'
' ToggleFormLock Macro
' Macro created 1/27/2004 by name removed
'
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields = False Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="password"
'if a password is used, add the line below after a space above
'Password:="myPassword"
Else
'if a password is used, add a comma after
'the last line and include the line below
'Password:="myPassword"
End If
End Sub
I found your code a little unwieldy and understand that it poses a problem for you. The abbreviated version below should be easier to understand and therefore easier for you to manage once you acquaint yourself with its own peculiarities. Note that I tested everything except the actual extraction and insertion of the building block, since you said it is working.
Option Explicit
' declare the name (so as to eliminate typos)
Const CmdName As String = "Select Location"
Sub AutoNew()
' 12 Oct 2017
SetCommandBar
End Sub
Sub AutoOpen()
' 12 Oct 2017
SetCommandBar
End Sub
Sub SetCommandBar()
' 12 Oct 2017
Dim MyBar As CommandBar
Dim MyCtl As CommandBarControl
Dim MyList() As String
Dim Cmd As CommandBar
Dim i As Integer
' delete the existing (so that you can modify it)
For Each Cmd In CommandBars
If Cmd.Name = CmdName Then
Cmd.Delete
Exit For
End If
Next Cmd
' in Word >= 2007 the commandbar will be displayed
' in the ribbon's Add-ins tab
Set MyBar = CommandBars.Add(Name:=CmdName, _
Position:=msoBarFloating, _
MenuBar:=True, _
Temporary:=True)
Set MyCtl = CommandBars(CmdName).Controls.Add( _
Type:=msoControlDropdown, _
Before:=1)
' Names must match Building Block names (without " Header")
MyList = Split(" South Portland, Bangor, Presque Isle", ",")
With MyCtl
.Caption = "Select Office Location"
.Style = msoComboLabel
For i = 0 To UBound(MyList)
.AddItem MyList(i)
Next i
.ListIndex = 1
.OnAction = "SetHeader"
End With
CommandBars(CmdName).Visible = True
End Sub
Sub SetHeader()
' 12 Oct 2017
Const BlockFile As String = "C:\Users\bex172\AppData\Roaming\Microsoft\" & _
"Document Building Blocks\1033\15\" & _
"Building Blocks.dotx"
Dim BlockID As String
SetFormLock False ' not needed if the document isn't locked
With ActiveWindow
If .View.SplitSpecial <> wdPaneNone Then .Panes(2).Close
With .ActivePane.View
If .Type = wdNormalView Or .Type = wdOutlineView Then
.Type = wdPrintView
End If
.SeekView = wdSeekCurrentPageHeader
End With
End With
BlockID = Trim(CommandBars(CmdName).Controls(1).Text) & " Header"
Templates.LoadBuildingBlocks
Application.Templates(BlockFile).BuildingBlockEntries(BlockID).Insert _
Where:=Selection.Range, _
RichText:=True
SetFormLock True ' not needed if the document isn't to be locked
End Sub
Sub SetFormLock(ByVal FormLock As Boolean)
' 12 Oct 2017
' call this procedure with either "True" or "False" as argument
' to either lock or unlock the form.
' The same password is used for unlocking and locking.
' MAKE SURE THE DOCUMENT IS UNLOCKED before changing the password!
Const Password As String = ""
Dim Doc As Document
Set Doc = ActiveDocument
With Doc
If .ProtectionType = wdNoProtection Then
If FormLock Then
' you can't set the protection while any other part of the document is active
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
' you may wish to specify another type of protection:
' this code protects all except FormFields
.Protect Type:=WdProtectionType.wdAllowOnlyFormFields, _
NoReset:=True, _
Password:=Password, _
UseIRM:=False, _
EnforceStyleLock:=False
End If
Else
If Not FormLock Then .Unprotect Password
End If
End With
End Sub
Your question didn't allow full understanding of your problem. It might have to do with the location of the code itself or with the protection. By making the code more transparent I hope that you will either be able to eliminate the problem or find the right question to ask.

Customize word right click menu

I have the following code to customize the right click menu:
Sub CreateMenuItem()
Dim MenuButton As CommandBarButton
With CommandBars("Text") 'Text, Lists and Tables
Set MenuButton = .Controls.Add(msoControlButton)
With MenuButton
.Caption = "Correct"
.Style = msoButtonCaption
.OnAction = "InsertCorrect"
End With
End With
End Sub
It works fine with text and lists, but only partially with tables:
With CommandBars("Tables")
I must select the whole table or a column then it works but not inside a cell. What is the name for the context menu inside a cell or for text inside a table cell?
I made this routine to see al the names of the CommandBars in Word:
Sub ListYourCommandBars()
For Each c In CommandBars
Debug.Print c.Name
Next
End Sub
Good news they are already sorted alphabetically. I found one called Table Cells. I tried it:
With CommandBars("Table Cells")
and it worked. Only thing, a cell or a number of cells must be "wholly selected". That is, the menu-item doesnt show up if you just enter inside the cell, you must select the cell "as a whole" (dunno how to say it better). Hope this helps.
I got it to work inside a table cell by adding the MenuButton to the following Built-In CommandBars: "Text", "Linked Text", "Table Text", "Font Paragraph", "Linked Headings", "Linked Table", "Linked Text", "Lists", "Table Cells", "Table Lists", "Tables", "Tables and Borders", and "Text Box".
I’m not sure which one actually did the trick. Here’s my code:
Private DisableEvents As Boolean
Private Sub UpdateRightClickMenus()
Dim MenuButton As CommandBarButton
Dim CommandBarTypes(100) As String
Dim i As Long
Dim PRChecklistIsSelected As Boolean
Dim CheckListTypeFound As Boolean
PRChecklist = True
ResetRightClickMenus
CommandBarTypes(0) = "Text"
CommandBarTypes(1) = "Linked Text"
CommandBarTypes(2) = "Table Text"
CommandBarTypes(3) = "Font Paragraph"
CommandBarTypes(4) = "Linked Headings"
CommandBarTypes(5) = "Linked Table"
CommandBarTypes(6) = "Linked Text"
CommandBarTypes(7) = "Lists"
CommandBarTypes(8) = "Table Cells"
CommandBarTypes(9) = "Table Lists"
CommandBarTypes(10) = "Tables"
CommandBarTypes(11) = "Tables and Borders"
CommandBarTypes(12) = "Text Box"
Dim cc As ContentControl
Set cc = FindContentControlByTag("ListBox_PR_TR")
If IsNull(cc) Then
DisableEvents = False
Exit Sub
End If
'Find Selected
For i = 1 To cc.DropdownListEntries.Count
If cc.Range.Text = "Product Review" Then
PRChecklistIsSelected = True
CheckListTypeFound = True
Exit For
End If
If cc.Range.Text = "Technical Review" Then
PRChecklistIsSelected = False
CheckListTypeFound = True
Exit For
End If
Next i
If CheckListTypeFound = False Then Exit Sub
For i = 0 To 12
With Application
If PRChecklistIsSelected Then
'Add right-click menu option to set as a Product Review comment
With .CommandBars(CommandBarTypes(i))
Set MenuButton = .Controls.Add(msoControlButton)
With MenuButton
.Caption = "Set as Product Review Comment"
.Style = msoButtonCaption
.OnAction = "Set_as_Product_Review_Comment"
End With
End With
Else
'Add right-click menu option to set as a Tech Review comment
With .CommandBars(CommandBarTypes(i))
Set MenuButton = .Controls.Add(msoControlButton)
With MenuButton
.Caption = "Set as Tech Review Comment"
.Style = msoButtonCaption
.OnAction = "Set_as_Tech_Review_Comment"
End With
End With
End If
End With
Next i
RightClickMenuItemsAdded = True
End Sub
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
If DisableEvents = True Then Exit Sub
Set cc = FindContentControlByTag("ListBox_PR_TR")
If IsNull(cc) Then
ResetRightClickMenus
DisableEvents = False
Exit Sub
End If
If cc.Range.Text = "Technical Review" Then
Find_PR_Style_ReplaceWith_TR_Style
End If
UpdateRightClickMenus
DisableEvents = False
End Sub
Private Sub Find_PR_Style_ReplaceWith_TR_Style()
Set StylePR = ThisDocument.Styles("Product Review Style")
Set StyleTR = ThisDocument.Styles("Technical Review Style")
With ThisDocument.Content.Find
.ClearFormatting
.Style = StylePR
With .Replacement
.ClearFormatting
.Style = StyleTR
End With
.Execute Forward:=True, Replace:=wdReplaceAll, FindText:="", ReplaceWith:=""
End With
End Sub
Private Sub Set_as_Tech_Review_Comment()
Set StyleTR = ThisDocument.Styles("Technical Review Style")
With ThisDocument
Selection.Style = StyleTR
SetCanContinuePreviousList
End With
End Sub
Private Sub Set_as_Product_Review_Comment()
Set StylePR = ThisDocument.Styles("Product Review Style")
With ThisDocument
Selection.Style = StylePR
SetCanContinuePreviousList
End With
End Sub
Private Sub SetCanContinuePreviousList()
Dim lfTemp As ListFormat
Dim intContinue As Integer
Dim oldListNumber As Single
Set lfTemp = Selection.Range.ListFormat
oldListNumber = lfTemp.ListValue
If Not (lfTemp.ListTemplate Is Nothing) Then
intContinue = lfTemp.CanContinuePreviousList( _
ListTemplate:=lfTemp.ListTemplate)
lfTemp.ApplyListTemplate _
ListTemplate:=lfTemp.ListTemplate, _
ContinuePreviousList:=False, _
ApplyTo:=wdListApplyToWholeList
If lfTemp.ListValue = oldListNumber Then
lfTemp.ApplyListTemplate _
ListTemplate:=lfTemp.ListTemplate, _
ContinuePreviousList:=True, _
ApplyTo:=wdListApplyToWholeList
End If
End If
Set lfTemp = Nothing
End Sub
Private Function FindContentControlByTag(Tag As String) As ContentControl
For Each cc In ThisDocument.ContentControls
If cc.Tag = Tag Then
Set FindContentControlByTag = cc
Exit Function
End If
Next
End Function
Private Sub ResetRightClickMenus()
Dim CommandBarTypes(100) As String
Dim i As Long
CommandBarTypes(0) = "Text"
CommandBarTypes(1) = "Linked Text"
CommandBarTypes(2) = "Table Text"
CommandBarTypes(3) = "Font Paragraph"
CommandBarTypes(4) = "Linked Headings"
CommandBarTypes(5) = "Linked Table"
CommandBarTypes(6) = "Linked Text"
CommandBarTypes(7) = "Lists"
CommandBarTypes(8) = "Table Cells"
CommandBarTypes(9) = "Table Lists"
CommandBarTypes(10) = "Tables"
CommandBarTypes(11) = "Tables and Borders"
CommandBarTypes(12) = "Text Box"
For i = 0 To 12
Application.CommandBars(CommandBarTypes(i)).Reset
Next i
RightClickMenuItemsAdded = False
End Sub
Private Sub Document_Open()
UpdateRightClickMenus
End Sub
Private Sub Document_Close()
ResetRightClickMenus
End Sub

VBA powerpoint - Macro for formatting notes

I'm trying to make a macro that can change all the text in all the notes of a powerpoint presentation to a specified font and fontsize (given through InputBoxes).
It seems to work but not in all the slides, some slides it just resets the fontsize to something way larger than what was given. anyone know what could go wrong?
Sub FormatNotes()
Dim intSlide As Integer
Dim strNotes As String
Dim nts As TextRange
Dim strFont, intSize
intSize = InputBox("Please enter font size", "fontsize", "12")
strFont = InputBox("Please enter font", "font type", "Calibri")
With ActivePresentation
For intSlide = 1 To .Slides.Count
Set nts = ActivePresentation.Slides(intSlide).NotesPage. _
Shapes.Placeholders(2).TextFrame.TextRange
With nts
If intSize = "" Then intSize = 12
.Paragraphs.Font.Size = intSize
.Paragraphs.Font.Name = strFont
End With
Next intSlide
End With
MsgBox ("FormatNotes uitgevoerd")
End Sub
Seems to work to me. I also tried it after deleting .Paragraphs as you don't need that if you want to set the whole text to the same type face and size. Do you have an example of it not working for investigation?
By the way, did you know that Notes formatting is not shown by default in PowerPoint and has to be turned on in the Outline view?
Original question is why code did not work for all slides. I think it has to do with fact the code used Placeholder(2) as hard value, so the code only works with TextRange in that Placeholder. If the NotesPage has more than one Placeholder, the code will not work for the other Placeholders.
My code shown here uses .HasTextFrame to determine if a Placeholder has text, and only attempts to set font size and type if this is true. (I used debug.print to see how far the code got, you can comment it out.)
Sub FormatNotes()
' Written 2020-08-29 P.Irving for myself
Dim mySlide As Integer, myPlace As Integer
Dim myNotes As String
Const mySize = "11", myFont = "Calibri"
With ActivePresentation ' qualify macro name
Debug.Print "Slide#", "LEN(Notes)", "LEFT(Notes,50)"
For mySlide = 1 To .Slides.Count
myNotes = ""
For myPlace = 1 To ActivePresentation.Slides(mySlide). _
NotesPage.Shapes.Placeholders.Count
' code copied from learn.microsoft.com/en-us/office/_
' vba/api/powerpoint.textrange.font
' this code does not attempt to SET nts
With ActivePresentation.Slides(mySlide). _
NotesPage.Shapes.Placeholders(myPlace)
If .HasTextFrame Then
With .TextFrame.TextRange.Font
.Size = mySize
.Name = myFont
'.Bold = True
'.Color.RGB = RGB(255, 127, 255)
End With
myNotes = myNotes & _
ActivePresentation.Slides(mySlide). _
NotesPage.Shapes.Placeholders(myPlace). _
TextFrame.TextRange
End If ' .HasText
End With
Next myPlace
Debug.Print mySlide, Len(myNotes), Left(myNotes, 50)
Next mySlide
End With
MsgBox "Applied to " & ActivePresentation.Slides.Count & " slides", _
vbOKOnly, "FormatNotes"
End Sub

command button is being renamed

I am having an issue with active x control command buttons being renamed in Word 2007 without the user actually renaming them. I have directly observed the user saving the document with embedded active x controls and the names appear to be okay when they open the document, but when they save the document, they are renamed.
For example, the name property for CommandButton11 will be renamed to CommandButton111. In some cases it appears that 1 is being added to the end of the Command Button Name so 10 becomes 101, while in other cases 1 is being added to the actual value of the command button so say CommandButton10 becomes CommandButton11. The code for the command buttons does not change, but because I reference the names of the individual command buttons within the code, it obviously breaks.
The purpose of the code is to embed an OLE object in the document and place it correctly in a table.
Below is the specific code for the command button:
Private Sub CommandButton10_Click()
wrdTbl = 1
wrdRow = 11
wrdCol = 2
Set obj = CommandButton10
Call buttontransformer
End Sub
Button transformer is as follows:
Private Sub buttontransformer()
If ActiveDocument.Tables(wrdTbl).Cell(wrdRow, wrdCol).Range.Text = Chr(13) & Chr(7) Then
obj.Caption = "Remove File"
Call OLEObjectAdd
Else
ActiveDocument.Tables(wrdTbl).Cell(wrdRow, wrdCol).Select
Selection.EndKey unit:=wdRow, Extend:=wdExtend
Selection.Delete
obj.Caption = "Click to Add File"
ireply = MsgBox("Add another file?", buttons:=vbYesNo, Title:="UPLOAD NEW FILE?")
If ireply = vbYes Then
obj.Caption = "Remove File"
Call OLEObjectAdd
Else
Exit Sub
End If
End If
End Sub
And OleObjectAdd is as follows:
Private Sub OLEObjectAdd()
Dim fd As FileDialog
Dim ofd As Variant
Dim FP As String
Dim FN As String
Dim Ext As String
Dim fType As String
'Selection.MoveRight Unit:=wdCharacter, Count:=1
Set fd = Application.FileDialog(msoFileDialogFilePicker)
ActiveDocument.Tables(wrdTbl).Cell(wrdRow, wrdCol + 1).Select
With fd
.ButtonName = "Select"
.AllowMultiSelect = False
.Filters.Clear
If .Show = -1 Then
For Each ofd In .SelectedItems
FP = ofd
Debug.Print FP
FN = Right(FP, Len(FP) - InStrRev(FP, "\"))
Debug.Print FN
Ext = Right(FP, Len(FP) - InStrRev(FP, "."))
Debug.Print Ext
Next ofd
On Error GoTo 0
Else
Exit Sub
End If
End With
If Ext = "pdf" Then
fType = "adobe.exe"
ElseIf Ext = "doc" Or Ext = "docx" Or Ext = "docm" Then
fType = "word.exe"
ElseIf Ext = "xls" Or Ext = "xlsx" Or Ext = "xlsm" Then
fType = "Excel.exe"
End If
Selection.InlineShapes.AddOLEObject ClassType:=fType, _
fileName:=FP, LinkToFile:=False, _
DisplayAsIcon:=True, IconFileName:= _
fType, IconIndex:=0, IconLabel:= _
FN
Selection.Move unit:=wdCell, Count:=-2
Selection = FN
End Sub
I had done the Microsoft Fixit to address the Active-X broken controls and it works fine on several other computers I have tested this on.
I have searched high and low for an answer and cant seem to find one. Any help would be appreciated.