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 / Programming / August 2006

Tip: Looking for answers? Try searching our database.

RE: VBA & Bookmarks

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lumpjaw - 16 Aug 2006 00:34 GMT
Greetings,

I am fairly new to this concept, so I will give the scenario and the the
problem.

I have 3 word documents; letter1.doc, letter2.doc, letter3.doc
In each of these three documents I have a text form field called 'job
number'.
Can I write a VB program that will ask a user for a job number, and then
insert that number in each of the three documents, if so, how?

Thanks.

-lumpjaw
Greg Maxey - 16 Aug 2006 01:05 GMT
You could use this:
Sub Scratchmacro()
Dim pJN As String
pJN = InputBox("Enter Job Number: ", "Job Number")
Documents.Open FileName:="C:\Test1.doc"
With ActiveDocument
 .Unprotect
 .FormFields("Jobnumber").Result = pJN
 .Protect wdAllowOnlyFormFields, True
 .Close SaveChanges:=wdSaveChanges
End With
Documents.Open FileName:="C:\Test2.doc"
With ActiveDocument
 .Unprotect
 .FormFields("Jobnumber").Result = pJN
 .Protect wdAllowOnlyFormFields, True
 .Close SaveChanges:=wdSaveChanges
End With
Documents.Open FileName:="C:\Test3.doc"
With ActiveDocument
 .Unprotect
 .FormFields("Jobnumber").Result = pJN
 .Protect wdAllowOnlyFormFields, True
 .Close SaveChanges:=wdSaveChanges
End With
End Sub

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Greetings,
>
[quoted text clipped - 10 lines]
>
> -lumpjaw
Lumpjaw - 17 Aug 2006 02:15 GMT
Hey Greg,

I got the code you suggested to work, but I am having one problem. After the
text is written into the other documents, the formfield box remains greyed
out, any way to change this? Thanks.

ps

I am using a docvariable

> You could use this:
> Sub Scratchmacro()
[quoted text clipped - 37 lines]
>>
>> -lumpjaw
Greg Maxey - 17 Aug 2006 02:32 GMT
I don't understand the problem.  I created three documents.  Test1, Test2
and Test3.  Each has a text formfield bookmarked "Jobnumber."  The documents
(form) are then protected, saved and closed.  I open a new document and
create the macro using the VBA editor:

Sub ScratchmacroII()
Dim pJN As String
Dim myArray
Dim i As Long
myArray = Split("C:\Test1.doc,C:\Test2.doc,C:\Test3.doc", ",")
pJN = InputBox("Enter Job Number: ", "Job Number")
For i = 0 To UBound(myArray)
Documents.Open FileName:=myArray(i)
With ActiveDocument
 .Unprotect
 .FormFields("Jobnumber").Result = pJN
 .Protect wdAllowOnlyFormFields, True
 .Close SaveChanges:=wdSaveChanges
End With
Next
End Sub

After the code is finished I can open any of the three document and the job
number is populated and I can enter and edit the field (is your formfield
fill-in enabled?).

What do you mean by "I am using a docvariable?"

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Hey Greg,
>
[quoted text clipped - 53 lines]
>>>
>>> -lumpjaw
Lumpjaw - 18 Aug 2006 00:49 GMT
Sorry Greg, my mistake.  After I wrote the note I figured out my problem, I
had a form text field with the shading on.  Thanks for the help, the code
works great.

-lumpjaw

>I don't understand the problem.  I created three documents.  Test1, Test2
>and Test3.  Each has a text formfield bookmarked "Jobnumber."  The
[quoted text clipped - 81 lines]
>>>>
>>>> -lumpjaw
Greg Maxey - 16 Aug 2006 01:21 GMT
or slightly abbreviated:

Sub ScratchmacroII()
Dim pJN As String
Dim myArray
Dim i As Long
myArray = Split("C:\Test1.doc,C:\Test2.doc,C:\Test3.doc", ",")
pJN = InputBox("Enter Job Number: ", "Job Number")
For i = 0 To UBound(myArray)
Documents.Open FileName:=myArray(i)
With ActiveDocument
 .Unprotect
 .FormFields("Jobnumber").Result = pJN
 .Protect wdAllowOnlyFormFields, True
 .Close SaveChanges:=wdSaveChanges
End With
Next
End Sub
Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Greetings,
>
[quoted text clipped - 10 lines]
>
> -lumpjaw
Lumpjaw - 16 Aug 2006 02:41 GMT
Thanks Greg, exactly what I was looking for.

-Lumpjaw

> or slightly abbreviated:
>
[quoted text clipped - 28 lines]
>>
>> -lumpjaw
 
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.