Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / April 2008

Tip: Looking for answers? Try searching our database.

Macro behaving differenlty on different computers

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
paraakaram - 10 Apr 2008 22:29 GMT
Hi there,

The problem is that, I have written this macro, which would find the "SET"
type of fields inside the document
and then replace the text inside the "SET Field" with text I pass

This is the macro

/*This would open the document which contains set field*/

Application.Documents.Open ("C:/Test Field.doc")
Application.Visible = True
Call merging                                                                
/*Here call is made to another macro */

/*This would try replacing the text inside the set field*/

If ActiveDocument.Fields.Count > 0 Then
For i = 1 To ActiveDocument.Fields.Count
ActiveDocument.Fields.Add
Range:=ActiveDocument.Fields.Item(1).Code.Previous, _
Type:=wdFieldEmpty, _
Text:="SET F256_1 NewText"
ActiveDocument.Fields.Update
Next
End If

The strange part here is, this works perfectly on my system (Word 2003)
but there is a system in my lab where this instead of replacing the text
inside the set field
would insert new set field in the document

It is very strange because only this system shows such a behavior (it has
msword 2002 SP3 )

Thanks & Kind Regards
Paraakaram
Graham Mayor - 11 Apr 2008 07:41 GMT
You are adding a field rather than replacing the content?
You also appear to have a redundant for/next loop?

Dim strCodes As String
strCodes = ActiveDocument.ActiveWindow.View.ShowFieldCodes
ActiveDocument.ActiveWindow.View.ShowFieldCodes = True
Selection.HomeKey
   With ActiveDocument.Fields(1)
       .Code.Text = Replace(.Code.Text, _
           .Code, "SET F256_1 NewText")
       .Update
   End With
ActiveDocument.ActiveWindow.View.ShowFieldCodes = strCodes

may be closer to what you want, if there is only the first field involved

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Hi there,
>
[quoted text clipped - 33 lines]
> Thanks & Kind Regards
> Paraakaram
paraakaram - 11 Apr 2008 08:42 GMT
Hi Graham

Thank you for your reply

Your reply is correct but there is a surprising fact here,

The macro I have written to replace the text inside the field
works fine for all the computers except one system.

What I mean is that, though the way I followed to achieve my requirement
is not perfectly correct unlike yours but it is achieving what I wanted on
all the
system except one, where the another "SET" field gets added instead of
replacing
action taking place.

Thank you for such a prompt reply

Kind Regards
Paraakaram

> You are adding a field rather than replacing the content?
> You also appear to have a redundant for/next loop?
[quoted text clipped - 49 lines]
> > Thanks & Kind Regards
> > Paraakaram
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.