Log in

View Full Version : assign a button



Scooter172
04-08-2011, 01:04 PM
Sub SendEmail()
'
' SendEmail Macro
'
'
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"C:\DOCUME~1\stonesa\LOCALS~1\Temp\Twins Game Summary.pdf", ExportFormat _
:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentWithMarkup, IncludeDocProps:=False, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
End SubI have a word doc that I have installed a command button on. I have written a macro that I want that button to command. I am having a brain cramp today I assigned it by macro name to the command button but when I run the code from the command button it does NOT open Outlook or attach it. :p

RonMcK
04-08-2011, 01:35 PM
Scooter,

Microsoft knowledgebase article 246299 (http://support.microsoft.com/kb/246299?app=ZWD&ver=12) offers the following code sample:

Sub Test()

'Add a command button to a new document
Dim doc As Word.Document
Dim shp As Word.InlineShape
Set doc = Documents.Add

Set shp = doc.Content.InlineShapes.AddOLEControl(ClassType:="Forms.CommandButton.1")
shp.OLEFormat.Object.Caption = "Click Here"

'Add a procedure for the click event of the inlineshape
'**Note: The click event resides in the This Document module
Dim sCode As String
sCode = "Private Sub " & shp.OLEFormat.Object.Name & "_Click()" & vbCrLf & _
" MsgBox ""You Clicked the CommandButton""" & vbCrLf & _
"End Sub"
doc.VBProject.VBComponents("ThisDocument").CodeModule.AddFromString sCode

End Sub


Please see the MS KB article for additional notes and suggestions.

HTH,

Scooter172
04-09-2011, 08:33 AM
Ron, this works great for creating a button. Iknow how to do that. What I have problems with is when I build the macro it performs. But when I run the macro it does nothing. It doesnt even give me a fail warning. in the lower bar of word It runs but outlook does not open with the attachment in place. :dunno :banghead: