Word 2010 command button not sending to email

PANTECH
NewLounger
Posts: 21
Joined: 20 May 2014, 18:12

Word 2010 command button not sending to email

Post by PANTECH »

The below code works with Word 2007 64bit but not Word 2010 64bit. The end user does not receive the email.

Code: Select all

Option Explicit


Private Sub CommandButton1_Click()
    Dim olApp As Object
    Dim olMsg As Object
    Dim olRec As Object
    Dim olDoc As Document

    On Error Resume Next
    Set olApp = GetObject(Class:="Outlook.Application")
    If olApp Is Nothing Then
        Set olApp = CreateObject(Class:="Outlook.Application")
        If olApp Is Nothing Then
            MsgBox "Can't start Outlook!", vbCritical
            Exit Sub
        End If
        olApp.Session.Logon
        
    End If
    On Error GoTo ErrHandler

    Call AltPrintScreen
    DoEvents
    Set olMsg = olApp.CreateItem(0)
    Set olRec = olMsg.Recipients.Add("his email address")
    olMsg.Subject = "WALKAROUND"
    
    olMsg.Display
    Set olDoc = olApp.ActiveInspector.WordEditor
    olDoc.Content.Paste
    olDoc.Content.InsertParagraphAfter
    olDoc.Content.InsertAfter "Here you go"
    
    olMsg.Send

ExitHandler:
    On Error Resume Next
    Exit Sub

ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
End Sub


Private Sub SpinButton1_Change()
    TextBox1.Text = SpinButton1.Value
    SpinButton1.Min = 0
    SpinButton1.Max = 9
End Sub

Private Sub SpinButton2_Change()
    TextBox2.Text = SpinButton2.Value
    SpinButton2.Min = 0
    SpinButton2.Max = 9
End Sub

Private Sub SpinButton3_Change()
    TextBox3.Text = SpinButton3.Value
    SpinButton3.Min = 0
    SpinButton3.Max = 9
End Sub

Private Sub SpinButton4_Change()
    TextBox4.Text = SpinButton4.Value
    SpinButton4.Min = 0
    SpinButton4.Max = 9
End Sub

Private Sub UserForm_Initialize()
    Dim ws As WdWindowState
    With Application
        ' Store current window state in variable
        ws = .WindowState
        ' Maximize application
        .WindowState = wdWindowStateMaximize
        ' Resize userform to application size
        Me.Width = .Width
        Me.Height = .Height
        ' Restore the application's original window state
        .WindowState = ws
    End With
End Sub

Sub CreateShortCut()
    Dim oWSH As Object
    Dim oShortcut As Object
    Dim sPathDeskTop As String

    Set oWSH = CreateObject("WScript.Shell")
    sPathDeskTop = oWSH.SpecialFolders("Desktop")

    Set oShortcut = oWSH.CreateShortCut(sPathDeskTop & "\" & _
        ActiveDocument.Name & ".lnk")
    With oShortcut
        .TargetPath = ActiveDocument.FullName
        .Save
    End With

    Set oWSH = Nothing
End Sub



User avatar
HansV
Administrator
Posts: 78512
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Word 2010 command button not sending to email

Post by HansV »

Word 2007 itself is always 32-bit. It can run on 32-bit Windows and on 64-bit Windows.

You mention that the end user does not receive the email. Does it appear in the Sent Items folder of the sender? Or does it remain in the Outbox folder? If neither, does the sender get an error message?
Best wishes,
Hans

PANTECH
NewLounger
Posts: 21
Joined: 20 May 2014, 18:12

Re: Word 2010 command button not sending to email

Post by PANTECH »

It is to go directly from the userform to the end users email. The userform should close after the command button it pressed. This process works in Word 2007 but not Word 2010. The end user receives nothing.

User avatar
HansV
Administrator
Posts: 78512
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Word 2010 command button not sending to email

Post by HansV »

Could you answer my questions?
Does it appear in the Sent Items folder of the sender? Or does it remain in the Outbox folder? If neither, does the sender get an error message?
Best wishes,
Hans

PANTECH
NewLounger
Posts: 21
Joined: 20 May 2014, 18:12

Re: Word 2010 command button not sending to email

Post by PANTECH »

The user of Word 2010 does not show anything in his sent folder, nothing in his outbox or no error.

User avatar
HansV
Administrator
Posts: 78512
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Word 2010 command button not sending to email

Post by HansV »

I'm afraid I cannot explain that. If the code fails, it should display an error message. It does work for me in Word 2010 (32-bit) on Windows 7 (64-bit). I don't have 64-bit Word 2010, so I cannot test there.

I assume that you did change the code for keybd_event as discussed in WORD 7 VBA- CODE NEEDS UPDATING TO A 64 BIT SYSTEM.
Best wishes,
Hans

PANTECH
NewLounger
Posts: 21
Joined: 20 May 2014, 18:12

Re: Word 2010 command button not sending to email

Post by PANTECH »

The end user says when he clicks submit he sees at the lower right hand corner of the screen - sent to clip board. Since I have never used Word 2010, I have no idea what that means. Oh, I did cut and paste your code.

User avatar
HansV
Administrator
Posts: 78512
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Word 2010 command button not sending to email

Post by HansV »

That may mean that the user displays the Office clipboard, It shouldn't prevent the macro from working though.
Best wishes,
Hans

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: Word 2010 command button not sending to email

Post by macropod »

Cross-posted at: http://www.msofficeforums.com/word-vba/ ... email.html" onclick="window.open(this.href);return false;
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184" onclick="window.open(this.href);return false;
Paul Edstein
[Fmr MS MVP - Word]