Hi Paul.
I'm working with on Word in Dutch, so it takes me a little work to translate.
In my Dotm file, all the code goes in the "this document" object, I can see the entire code on the general and document tab.
When I fire the dotm, I have the same code under "project MArc", but under projest, document1 there is nog code at all.
In the beginning of my code, I do use a private sub Document_new. In that one I chage the directory where to put files.
And now, a very stupid question... When I made the Form, I used the tab "Developers" from word itself. With that one, I inserted the place where the picture had to come, in cell of a table. (With help of the control-icons you can see in that tab) In English: Controlelements?
Somewhere I believe that is thing I'm doing wrong...
Would you take a look at the entire code?
I had to change the email and directories, since I could get the reply posted...
Thanks again,
Marc
This is the entire code (with still some testMsgBox in the doc_new routine)
Private Sub CommandButton1_Click()
CommandButton1.Enabled = True
'CommandButton1.Caption = "VERZONDEN"
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Dim docName As String
Dim pdfPath As String
On Error Resume Next
'Controleren of Outlook gestart is
Set appOutlook = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook is niet gestart
Set appOutlook = CreateObject("Outlook.Application")
bStart = True
End If
'Document opslaan
ChDir "//srv03/bewoners"
Set Doc = ActiveDocument
docName = "Vermissingsdocument DOMINO "
'Document opslaan als PDF in de temp map
pdfPath = Environ("temp") & "\"
ActiveDocument.ExportAsFixedFormat _
OutputFileName:=pdfPath & docName & ".pdf", _
ExportFormat:=wdExportFormatPDF
'Nieuw e-mailbericht object maken
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
'Maak een Outlook object en een nieuw mail bericht en verzend deze
Set Outapp = CreateObject("Outlook.Application")
Set Outmail = Outapp.CreateItem(0)
With EmailItem
.Subject = "Vermissing DOMINO"
.Body = "Bijgesloten het ingevulde vermissingsdocument" & vbCrLf & _
"WZC DOMINO VZW" & vbCrLf
.BCC = ""
.CC = my emailadres .To = ""
.Attachments.Add pdfPath & docName & ".pdf"
.Send
End With
'Loop 1 sec om Outlook de kans te geven het e-mailbericht te versturen
s = Timer
Do While Timer < s + 1
DoEvents
Loop
'Opruimen
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
Set Outapp = Nothing
Set Outmail = Nothing
End Sub
Private Sub document_new()
MsgBox "Greetings", vbOKOnly, "Greetings"
ChangeFileOpenDirectory 'Directory where I want to put my docs'
Dialogs(wdDialogFileOpen).Show
End Sub
Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
Dim StrPath As String
If ContentControl.Title = "ClipArt" Then
With Application.Dialogs(wdDialogInsertPicture)
StrPath = Options.DefaultFilePath(Path:=wdPicturesPath)
Options.DefaultFilePath(Path:=wdPicturesPath) = ' The place where I want to find my Picture'
.Update
If .Show = True Then
With ContentControl.Range
If .InlineShapes.Count > 1 Then .InlineShapes(1).Delete
End With
End If
Options.DefaultFilePath(Path:=wdPicturesPath) = StrPath
End With
End If
End Sub