Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-19-2014, 03:31 AM
tariqaleed2 tariqaleed2 is offline insert fields mail merge in vba Windows 7 32bit insert fields mail merge in vba Office 2010 32bit
Novice
insert fields mail merge in vba
 
Join Date: Jul 2014
Posts: 14
tariqaleed2 is on a distinguished road
Default insert fields mail merge in vba

I have a Word document is linked to a database ( mail-merge )



How i can replace the word "tariq" by Parameter merger «FirstName»
Reply With Quote
  #2  
Old 08-19-2014, 03:35 AM
macropod's Avatar
macropod macropod is offline insert fields mail merge in vba Windows 7 32bit insert fields mail merge in vba Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,230
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Why don't you simply insert the required mergefield into the mailmerge main document from the outset?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 08-19-2014, 04:23 AM
tariqaleed2 tariqaleed2 is offline insert fields mail merge in vba Windows 7 32bit insert fields mail merge in vba Office 2010 32bit
Novice
insert fields mail merge in vba
 
Join Date: Jul 2014
Posts: 14
tariqaleed2 is on a distinguished road
Default

I have users using different fields of the same database to make a mail merge in variable document
I found code that helps me ,but minus (insert fields mail merge by vba)
Regards
Reply With Quote
  #4  
Old 08-19-2014, 04:46 AM
macropod's Avatar
macropod macropod is offline insert fields mail merge in vba Windows 7 32bit insert fields mail merge in vba Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,230
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Why don't you either use different mailmerge main documents or use fields within them to vary the output? No VBA required. A mailmerge main document can even have fields that conditionally insert content from other documents.

From what I've seen of your posts so far, it seems you're trying to force VBA to do something because you haven't learnt to use the other tools. Rather like the apprentice with a hammer - everything looks like a nail.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 08-20-2014, 12:59 PM
tariqaleed2 tariqaleed2 is offline insert fields mail merge in vba Windows 7 32bit insert fields mail merge in vba Office 2010 32bit
Novice
insert fields mail merge in vba
 
Join Date: Jul 2014
Posts: 14
tariqaleed2 is on a distinguished road
Default

Thanks macropod for the advice and help .


This code was modified is working well , this is what I want, but it does not work in the text box, can possible modify it to be working in the text box
Greetings to all

Sub FindIt()
Dim blnFound As Boolean



Dim rngFound As Range
Dim strTheText As String


Application.ScreenUpdating = False
For i = 0 To 4
Selection.HomeKey wdStory
Selection.Find.Text = "TARIQ"
blnFound = Selection.Find.Execute
If blnFound Then
Selection.MoveStartWhile wdWord
Set rng1 = Selection.Range

ActiveDocument.MailMerge.Fields.Add Range:=Selection.Range, Name:="FirstName"
End If
'move back to beginning
Selection.HomeKey wdStory
Next
Application.ScreenUpdating = True
End Sub
Reply With Quote
  #6  
Old 08-20-2014, 01:34 PM
macropod's Avatar
macropod macropod is offline insert fields mail merge in vba Windows 7 64bit insert fields mail merge in vba Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,230
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

I have previously given you code for finding textbox content. Even so, it is unwise to use mergefields in textboxes. Furthermore, instead of your brute-force VBA approach you should, as I've already said, use field coding (or different mailmerge main documnents) to manage the variables.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 08-21-2014, 12:21 AM
tariqaleed2 tariqaleed2 is offline insert fields mail merge in vba Windows 7 32bit insert fields mail merge in vba Office 2010 32bit
Novice
insert fields mail merge in vba
 
Join Date: Jul 2014
Posts: 14
tariqaleed2 is on a distinguished road
Default

Finally, this code is required
Thank you macropod and thank for all

Sub FindIt11()
Application.ScreenUpdating = True
For i = 0 To 10
Selection.HomeKey wdStory
With ActiveDocument.Range.Find
.Text = "TARIQ"
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceNone
If .Found = True Then
.Parent.Select
ActiveDocument.MailMerge.Fields.Add Range:=Selection.Range, Name:="FirstName"
End If


End With
For Each iShp2 In ActiveDocument.Shapes
If iShp2.TextFrame.HasText = True Then
With iShp2.TextFrame.TextRange.Find
.Text = "TARIQ"
.Execute Replace:=wdReplaceNone
If .Found = True Then
.Parent.Select
ActiveDocument.MailMerge.Fields.Add Range:=Selection.Range,Name:="FirstName"
'
End If
End With
End If
Next iShp2
Next i


Application.ScreenUpdating = True


End Sub
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
insert fields mail merge in vba Typing Mail Merge Fields instead of clicking them? Mjpunj Mail Merge 1 06-20-2014 05:28 PM
Mail Merge Directory - Combining fields officegirl Mail Merge 1 03-21-2013 11:02 PM
insert fields mail merge in vba Mail Merge only produces 15 fields fm 22 Galceran Mail Merge 2 02-10-2013 05:47 PM
insert fields mail merge in vba Conditional merge fields in mail merge Aude Mail Merge 1 01-06-2012 07:38 PM
insert fields mail merge in vba Mail Merge truncating 'some' of the text fields......Not sure what to do sssb2000 Mail Merge 5 09-26-2010 09:40 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:04 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft