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
very basic inventory software in ms access
Javascript
SSL Error 70, Expired Security Certificate
Can't mount database after power failure
How do I Create new SharePoint server farm Database on different drive on same server
How do I Fix a RUNDLL Error
Run-time error '2587' Report Problems can't complete the Output operation
What is best for SEO? Whole site or partial site secure?
8 disk RAID-10 on OpenSuse
Hey, my Quake 4 won't wun under Vista, what gives?