Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
[email protected] j.nijkamp@kroesewevers.nl is offline
external usenet poster
 
Posts: 6
Default Mailmerge macro doesn't work in WORD 2007

Ive been using a macro to perform a mailmerge in wordxp. We're
planning to go to office 2007, so im testing that version at the
moment. However, the macro in word xp doesnt work for 2007, hope any1
can help me.

This is the macro

Sub SamenVoegen()

Dim fFieldText() As String
Dim iCount As Integer
Dim fField As FormField
Dim sWindowMain, sWindowMerge As String

With ActiveDocument
ChangeFileOpenDirectory "K:\Clienten"
ActiveDocument.SaveAs FileName:="u:\a.dot", FileFormat:=wdFormatDOT

On Error GoTo ErrHandler

sWindowMain = ActiveWindow.Caption
If ActiveDocument.ProtectionType wdNoProtection Then
ActiveDocument.Unprotect
End If

For Each afield In ActiveDocument.FormFields
If afield.Type = wdFieldFormTextInput Then
ReDim Preserve fFieldText(1, iCount + 1)
fFieldText(0, iCount) = afield.Result
fFieldText(1, iCount) = afield.Name
afield.Select
Selection.TypeText "" & fFieldText(1, iCount) & "PlaceHolder"
iCount = iCount + 1

End If

Next afield

ActiveDocument.MailMerge.Destination = wdSendToNewDocument
ActiveDocument.MailMerge.Execute

doFindReplace iCount, fField, fFieldText()

ActiveDocument.Protect Password:="", Noreset:=True, _
Type:=wdAllowOnlyFormFields

sWindowMerge = ActiveWindow.Caption

Windows(sWindowMain).Activate

doFindReplace iCount, fField, fFieldText()

ActiveDocument.Protect Password:="", Noreset:=True, _
Type:=wdAllowOnlyFormFields

Windows(sWindowMerge).Activate

ErrHandler:

End With
End Sub

Sub doFindReplace(iCount As Integer, fField As FormField, _
fFieldText() As String)

ActiveDocument.Close

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting

With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False


For i = 0 To iCount


Do While .Execute(FindText:="" & fFieldText(1, i) _
& "PlaceHolder") = True


Set fField = Selection.FormFields.Add _
(Range:=Selection.Range, Type:=wdFieldFormTextInput)


fField.Result = fFieldText(0, i)
fField.Name = fFieldText(1, i)
Loop


Selection.HomeKey Unit:=wdStory

Next
End With

With ActiveDocument
.Protect Type:=wdAllowOnlyFormFields, Noreset:=True, Password:=""

Dim sDatum As String
Dim sBetreft As String

With ActiveDocument
If ActiveDocument.Bookmarks.Exists("Datum") Then
sDatum = ActiveDocument.FormFields("Datum").Result
With Dialogs(wdDialogFileSummaryInfo)
.Execute
End With
End If
End With

With ActiveDocument
If ActiveDocument.Bookmarks.Exists("Betreft") Then
sBetreft = ActiveDocument.FormFields("Betreft").Result
With Dialogs(wdDialogFileSummaryInfo)
.Execute
End With
End If
End With

Dim ffItem As Word.FormField
Dim lngIndex As Long

With ActiveDocument
If ActiveDocument.ProtectionType wdNoProtection Then
ActiveDocument.Unprotect

For lngIndex = ActiveDocument.Content.FormFields.Count To 1 Step
-1

Set ffItem = ActiveDocument.Content.FormFields(lngIndex)
ffItem.Range.Text = ffItem.Result
Next
End If
End With

With ActiveDocument
.Protect Type:=wdAllowOnlyFormFields, Noreset:=True, Password:=""
End With

With ActiveDocument
ChangeFileOpenDirectory "K:\Clienten"
With Dialogs(wdDialogFileSaveAs)
.Name = Format(Date, "yymmdd") & " - " & sBetreft
.Show
End With
End With

ActiveDocument.Close

End With

ActiveDocument.Close

End Sub


Thanks in advance,
Jasper

  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Mailmerge macro doesn't work in WORD 2007

When you say it "doesnt work" exactly what do you mean? Does it produce and
error message that you can debug?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

wrote in message
...
Ive been using a macro to perform a mailmerge in wordxp. We're
planning to go to office 2007, so im testing that version at the
moment. However, the macro in word xp doesnt work for 2007, hope any1
can help me.

This is the macro

Sub SamenVoegen()

Dim fFieldText() As String
Dim iCount As Integer
Dim fField As FormField
Dim sWindowMain, sWindowMerge As String

With ActiveDocument
ChangeFileOpenDirectory "K:\Clienten"
ActiveDocument.SaveAs FileName:="u:\a.dot", FileFormat:=wdFormatDOT

On Error GoTo ErrHandler

sWindowMain = ActiveWindow.Caption
If ActiveDocument.ProtectionType wdNoProtection Then
ActiveDocument.Unprotect
End If

For Each afield In ActiveDocument.FormFields
If afield.Type = wdFieldFormTextInput Then
ReDim Preserve fFieldText(1, iCount + 1)
fFieldText(0, iCount) = afield.Result
fFieldText(1, iCount) = afield.Name
afield.Select
Selection.TypeText "" & fFieldText(1, iCount) & "PlaceHolder"
iCount = iCount + 1

End If

Next afield

ActiveDocument.MailMerge.Destination = wdSendToNewDocument
ActiveDocument.MailMerge.Execute

doFindReplace iCount, fField, fFieldText()

ActiveDocument.Protect Password:="", Noreset:=True, _
Type:=wdAllowOnlyFormFields

sWindowMerge = ActiveWindow.Caption

Windows(sWindowMain).Activate

doFindReplace iCount, fField, fFieldText()

ActiveDocument.Protect Password:="", Noreset:=True, _
Type:=wdAllowOnlyFormFields

Windows(sWindowMerge).Activate

ErrHandler:

End With
End Sub

Sub doFindReplace(iCount As Integer, fField As FormField, _
fFieldText() As String)

ActiveDocument.Close

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting

With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False


For i = 0 To iCount


Do While .Execute(FindText:="" & fFieldText(1, i) _
& "PlaceHolder") = True


Set fField = Selection.FormFields.Add _
(Range:=Selection.Range, Type:=wdFieldFormTextInput)


fField.Result = fFieldText(0, i)
fField.Name = fFieldText(1, i)
Loop


Selection.HomeKey Unit:=wdStory

Next
End With

With ActiveDocument
.Protect Type:=wdAllowOnlyFormFields, Noreset:=True, Password:=""

Dim sDatum As String
Dim sBetreft As String

With ActiveDocument
If ActiveDocument.Bookmarks.Exists("Datum") Then
sDatum = ActiveDocument.FormFields("Datum").Result
With Dialogs(wdDialogFileSummaryInfo)
.Execute
End With
End If
End With

With ActiveDocument
If ActiveDocument.Bookmarks.Exists("Betreft") Then
sBetreft = ActiveDocument.FormFields("Betreft").Result
With Dialogs(wdDialogFileSummaryInfo)
.Execute
End With
End If
End With

Dim ffItem As Word.FormField
Dim lngIndex As Long

With ActiveDocument
If ActiveDocument.ProtectionType wdNoProtection Then
ActiveDocument.Unprotect

For lngIndex = ActiveDocument.Content.FormFields.Count To 1 Step
-1

Set ffItem = ActiveDocument.Content.FormFields(lngIndex)
ffItem.Range.Text = ffItem.Result
Next
End If
End With

With ActiveDocument
.Protect Type:=wdAllowOnlyFormFields, Noreset:=True, Password:=""
End With

With ActiveDocument
ChangeFileOpenDirectory "K:\Clienten"
With Dialogs(wdDialogFileSaveAs)
.Name = Format(Date, "yymmdd") & " - " & sBetreft
.Show
End With
End With

ActiveDocument.Close

End With

ActiveDocument.Close

End Sub


Thanks in advance,
Jasper



  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
[email protected] j.nijkamp@kroesewevers.nl is offline
external usenet poster
 
Posts: 6
Default Mailmerge macro doesn't work in WORD 2007

well actually i found out that the mailmergedatafields from our CRM
weren't there.

I made the template all over from scratch, but i cant get the safety
on now...:-)

kinda sucks, cause i need the safety on to show the content of
themergefields from our crm and not the fieldcodes.

Any ideas?

  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Mailmerge macro doesn't work in WORD 2007

What do you mean by "safety on"?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

wrote in message
...
well actually i found out that the mailmergedatafields from our CRM
weren't there.

I made the template all over from scratch, but i cant get the safety
on now...:-)

kinda sucks, cause i need the safety on to show the content of
themergefields from our crm and not the fieldcodes.

Any ideas?



  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
[email protected] j.nijkamp@kroesewevers.nl is offline
external usenet poster
 
Posts: 6
Default Mailmerge macro doesn't work in WORD 2007

On 30 mei, 00:36, "Doug Robbins - Word MVP"
wrote:
What do you mean by "safety on"?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

wrote in message

...



well actually i found out that the mailmergedatafields from our CRM
weren't there.


I made the template all over from scratch, but i cant get the safety
on now...:-)


kinda sucks, cause i need the safety on to show the content of
themergefields from our crm and not the fieldcodes.


Any ideas?- Tekst uit oorspronkelijk bericht niet weergeven -


- Tekst uit oorspronkelijk bericht weergeven -


Protection on certain sections of the template


  #6   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Mailmerge macro doesn't work in WORD 2007

You do not need to protect the document to hide the display of mergefields.
Use:

If ActiveWindow.View.ShowFieldCodes = True Then
ActiveWindow.View.ShowFieldCodes = False
End If


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

wrote in message
...
On 30 mei, 00:36, "Doug Robbins - Word MVP"
wrote:
What do you mean by "safety on"?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

wrote in message

...



well actually i found out that the mailmergedatafields from our CRM
weren't there.


I made the template all over from scratch, but i cant get the safety
on now...:-)


kinda sucks, cause i need the safety on to show the content of
themergefields from our crm and not the fieldcodes.


Any ideas?- Tekst uit oorspronkelijk bericht niet weergeven -


- Tekst uit oorspronkelijk bericht weergeven -


Protection on certain sections of the template



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mailmerge from Access 2007 to Word 2007 .docx document Russell Profitt[_3_] Mailmerge 0 March 20th 08 12:16 PM
Word 2007 and Outlook 2007 e-mail MailMerge does not complete Account Manager Mailmerge 1 July 2nd 07 09:13 AM
hyperlink does not work in email prepared in word for mailmerge bayside Mailmerge 1 March 28th 07 07:24 AM
Word mailmerge to PDF macro Martin Mailmerge 2 April 13th 06 06:31 AM
WORD mailmerge field switchs do not work George R Mailmerge 3 May 27th 05 05:19 PM


All times are GMT +1. The time now is 05:02 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"