[VBA] Mail verzenden via VBA in Word

Pagina: 1
Acties:
  • 154 views sinds 30-01-2008

  • Coolhva
  • Registratie: Juni 2003
  • Laatst online: 29-12-2024

Coolhva

Dr. Zero Trust

Topicstarter
Ik ben bezig om een nieuw RMA formulier in elkaar aan het zetten.
Vroeger werd deze uitgeprint en gefaxed maar tegenwoordig moet het gemaild worden.

Nu ben ik al een paar uurtjes aan het zoeken op google en got en nieuwsgroepen om een werkende code te krijgen om een word document te verzenden via e-mail.

Tot nu toe werkt niets van wat ik heb gevonden. Alleen de routingslip methode werkt maar dan kan je de body niet aanpassen en krijg je rare vragen als je de mail opent.

De code van http://word.mvps.org/FAQs/InterDev/SendMail.htm:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Sub SendDocumentAsAttachment()

Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem

On Error Resume Next

If Len(ActiveDocument.Path) = 0 Then
    MsgBox "Document needs to be saved first"
    Exit Sub
End If

Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
    Set oOutlookApp = CreateObject("Outlook.Application")
    bStarted = True
End If

Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
    .To = "recipient@mail.com"
    .Subject = "New subject"
    'Add the document as an attachment, you can use the .displayname property
    'to set the description that's used in the message
    .Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
      DisplayName:="Document as attachment"
    .Send
End With

If bStarted Then
    oOutlookApp.Quit
End If

Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub


werkt helaas niet omdat hij zegt dat Outlook.Appliction niet gedefinieerd is.
Ik gebruik Outlook 2003 en Outlook 2000.

Al iemand die het hier wel gelukt is?

  • Coolhva
  • Registratie: Juni 2003
  • Laatst online: 29-12-2024

Coolhva

Dr. Zero Trust

Topicstarter
Stom Stom Stom.

Staat duidelijk in de pagina dat je de Outlook Libs moet laden..

Na bij Extra --> Verwijzingen Microsoft Outlook te hebben aangevinkt doet hij het wel ...

Topic mag dicht :)

Verwijderd

Toch wel grappig. Heb het ook wel eens.
Ben je je probleem aan het uittypen bent kom je erachter wat het probleem was :)

  • curry684
  • Registratie: Juni 2000
  • Laatst online: 17-12 01:59

curry684

left part of the evil twins

Hum dit is idd nog iets te kansloos zelfs om als knowledge base item open te blijven ;)

Professionele website nodig?


Dit topic is gesloten.