Microsoft
Software
Hardware
Network
Question : Create Button Macro-- Move to End of Document
I have a macro that creates a button, but I want it to put the button at the end of the document:
Sub AddCommandButton(ButtonNam
e As String)
'*************************
**********
**********
**
'*Note: For this to work, you must have a reference to Microsoft's VB for Apps Ext.
'* 1. In the VBA IDE, click on the 'Tools' menu item and select 'References...'
'* from the drop-down list.
'* 2. In the 'Available References:' box of the 'References' window, scroll down
'* to 'Microsoft Visual Basic for Applications Extensibility n.n'
'* 3. Click on the check box beside the name and then click OK near the top right
'* of the dialog box.
'*************************
**********
**********
***
Dim vbp As VBProject
Dim vbComp As VBComponent
Dim ILS As InlineShape
********'This doesn't seem to do it:
Selection.EndKey unit:=wdStory
Set ILS = ActiveDocument.InlineShape
s.AddOLECo
ntrol("For
ms.Command
Button.1")
Select Case ButtonName
Case "GenDocs"
ILS.OLEFormat.Object.Capti
on = "Generate Documents"
ILS.OLEFormat.Object.Name = "GenerateDocs"
ILS.OLEFormat.Object.AutoS
ize = True
Set vbp = ActiveDocument.VBProject
Set vbComp = vbp.VBComponents("ThisDocu
ment")
vbComp.CodeModule.AddFromS
tring "Sub GenerateDocs_Click()" & vbCrLf & _
" Call GenDocs " & vbCrLf & _
"End Sub"
Case "UpdateColor"
ILS.OLEFormat.Object.Capti
on = "Update Cell Colors"
ILS.OLEFormat.Object.Name = "UpdateColor"
ILS.OLEFormat.Object.AutoS
ize = True
Set vbp = ActiveDocument.VBProject
Set vbComp = vbp.VBComponents("ThisDocu
ment")
vbComp.CodeModule.AddFromS
tring "Sub UpdateColor_Click()" & vbCrLf & _
" UpdateCellColors" & vbCrLf & _
"End Sub"
Case "NoColor"
ILS.OLEFormat.Object.Capti
on = "Remove Cell Colors"
ILS.OLEFormat.Object.Name = "NoColor"
ILS.OLEFormat.Object.AutoS
ize = True
Set vbp = ActiveDocument.VBProject
Set vbComp = vbp.VBComponents("ThisDocu
ment")
vbComp.CodeModule.AddFromS
tring "Sub NoColor_Click()" & vbCrLf & _
" RemoveColor" & vbCrLf & _
"End Sub"
End Select
End Sub
Answer : Create Button Macro-- Move to End of Document
Thanks Rajesh - this is the line that works for me if I'm at the top of the document and run this - it puts the command button at the end of the document:
Selection.EndKey Unit:=wdStory
Selection.InlineShapes.Add
OLEControl
ClassType:="Forms.CommandB
utton.1"
Random Solutions
Powershell export-csv -delimiter parameter not working
Microsoft, Windows , XP SP2, Task Scheduler - Open Browser without Window
Fedora Installation
"OPen With" Problem
HP t5720 thin client boots to user automatically used to boot to admin. How do I change it back.
Shared IP Address on Linux and Apache webserver
HP, Pavilion, DV9548ca, XP downgrade; video drivers won't install
Offline Address Book, Outlook doesnt show any
Premiere 1.5 >> FLV possible?
copy Outlook 2007 Master category list to another computer