AnsweredAssumed Answered

Email from SW

Question asked by Hrituc Alexandru on Nov 3, 2015
Latest reply on Nov 3, 2015 by Ivana Kolin

Hi,

     I try to make a macro to send mail from sw with outlook...

How can I add text there?? ...with:  myItem.body = "" disappear signature

 

1.jpg

 

 

 

 

Option Explicit

 

 

Dim swModel As Object

Dim Model As Object

Dim swApp As Object

Dim Msg As String

Dim URL As String

 

 

Sub Main()

Dim strSigName As String

  Dim myOlApp As Outlook.Application

   Dim myItem As Outlook.MailItem

    Dim objItem As Object

    Dim objInsp As Outlook.Inspector

    ' requires a project reference to the

    ' Microsoft Word library

    Dim objDoc As Word.Document

    Dim objSel As Word.Selection

    ' requires a project reference to the

    ' Microsoft Office library

    Dim objCB As Office.CommandBar

    Dim objCBP As Office.CommandBarPopup

    Dim objCBB As Office.CommandBarButton

    Dim colCBControls As Office.CommandBarControls

    On Error Resume Next

 

    Set objInsp = Application.ActiveInspector

   

    Set swApp = CreateObject("SldWorks.Application")

    Set Model = swApp.ActiveDoc

    

    If Not objInsp Is Nothing Then

        Set objItem = objInsp.CurrentItem

        If objItem.Class = olMail Then  ' editor is WordMail

            If objInsp.EditorType = olEditorWord Then

                ' next statement will trigger security prompt

                ' in Outlook 2002 SP3

                Set objDoc = objInsp.WordEditor

                Set objSel = objDoc.Application.Selection

                If objDoc.Bookmarks("_MailAutoSig") Is Nothing Then

                    objDoc.Bookmarks.Add Range:=objSel.Range, Name:="_MailAutoSig"

                End If

                objSel.GoTo What:=wdGoToBookmark, Name:="_MailAutoSig"

                Set objCB = objDoc.CommandBars("AutoSignature Popup")

                If Not objCB Is Nothing Then

                    Set colCBControls = objCB.Controls

                End If

            Else ' editor is not WordMail

                ' get the Insert | Signature submenu

                Set objCBP = Application.ActiveInspector.CommandBars.FindControl(, 31145)

                If Not objCBP Is Nothing Then

                    Set colCBControls = objCBP.Controls

                End If

            End If

        End If

        If Not colCBControls Is Nothing Then

            For Each objCBB In colCBControls

                If objCBB.Caption = strSigName Then

                    objCBB.Execute ' **** see remarks

                    Exit For

                End If

            Next

        End If

    End If

   

    Set objInsp = Nothing

    Set objItem = Nothing

    Set objDoc = Nothing

    Set objSel = Nothing

    Set objCB = Nothing

    Set objCBB = Nothing

 

   Set myOlApp = New Outlook.Application

   Set myItem = myOlApp.CreateItem(olMailItem)

   'myItem.SentOnBehalfOfName = "Edson"

   myItem.To = "AAAAAAAAAAAAAAAA"

   myItem.CC = "BBBBBBBBBBBBBBBB"

   myItem.Subject = "CCCCCCCCCCC  " & Model.GetTitle

   myItem.Display

  

 

 

   

   

   'myItem.Save

 

End Sub

Outcomes