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 / November 2004

Tip: Looking for answers? Try searching our database.

Add Text and Text box on every page

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Natalie Dang - 05 Nov 2004 04:34 GMT
Hi all,

I'm trying to add a line of text and a text box on every page, but they
only show on the first page.  Please find my code below:

Dim ileft As Single
Dim iTop As Single
Dim iTotalPages As Integer
Dim iPage As Integer
Dim sText As String
Private objWord As Word.Application
Private objDoc As Word.Document
Dim oTextBox As Word.Shape
Dim oPageStart As Word.Range

Set objWord = New Word.Application
objWord.Documents.Open App.Path & "\test.doc"

Set objDoc = objWord.ActiveDocument

sText = "PRINT DATE: " & FormatDateTime(Now, vbShortDate)

iTop = objDoc.PageSetup.PageHeight - 100
ileft = objDoc.PageSetup.LeftMargin
iTotalPages = objDoc.ComputeStatistics(wdStatisticPages)

For iPage = 1 To iTotalPages

    Set oPageStart = objDoc.GoTo(what:=wdGoToPage, Which:=wdGoToAbsolute,
Count:=iPage)

iCount = oPageStart.Sections.Count
iTop = oPageStart.PageSetup.PageHeight - 100
ileft = oPageStart.PageSetup.LeftMargin

oPageStart.Document.Shapes.AddTextEffect msoTextEffect2, sText,
"Arial", 14, msoCTrue, msoFalse, ileft, iTop
Set oTextBox =
oPageStart.Document.Shapes.AddTextbox(msoTextOrientationHorizontal, _
Left:=ileft
+ 400, Top:=50, _
Width:=100,
Height:=70)

oTextBox.TextFrame.TextRange.Font.Name = "Point Arial"
oTextBox.TextFrame.TextRange.Font.Size = "10"
oTextBox.TextFrame.TextRange = "Work Order number " & vbCrLf &
vbCrLf & " TESTFY"
Next iPage

objWord.Visible = True

objWord.Quit wdDoNotSaveChanges

Could any one help?

Many thanks in advance

---
Message posted from http://www.ExcelForum.com/
Luke Skywalker - 08 Nov 2004 07:25 GMT
After running your code, all text boxes and wordarts are created in the
first page. To achieve the goal, I suggest you using the browser object. I
have added the code below for your reference and done a test. It should
work.

For more information about the browser object, refer to the VBA help in
Word.

Hope this helps.

Modified Code
==============
Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim oTextBox As Word.Shape
Dim oPageStart As Word.Range
Dim oBrowser As Word.Browser

Set objWord = New Word.Application
objWord.Documents.Open App.Path & "\test.doc"

Set objDoc = objWord.ActiveDocument

sText = "PRINT DATE: " & FormatDateTime(Now, vbShortDate)

iTop = objDoc.PageSetup.PageHeight - 100
ileft = objDoc.PageSetup.LeftMargin
iTotalPages = objDoc.ComputeStatistics(wdStatisticPages)

Set oBrowser = objDoc.Application.Browser

For iPage = 1 To iTotalPages

Set oPageStart = objDoc.GoTo(what:=wdGoToPage, Which:=wdGoToAbsolute, _
Count:=iPage)

iCount = oPageStart.Sections.Count
iTop = oPageStart.PageSetup.PageHeight - 100
ileft = oPageStart.PageSetup.LeftMargin

oPageStart.Document.Shapes.AddTextEffect msoTextEffect2, sText, _
"Arial", 14, msoCTrue, msoFalse, ileft, iTop
Set oTextBox =
oPageStart.Document.Shapes.AddTextbox(msoTextOrientationHorizontal, _
Left:=ileft + 400, Top:=50, Width:=100, Height:=70)

oTextBox.TextFrame.TextRange.Font.Name = "Point Arial"
oTextBox.TextFrame.TextRange.Font.Size = "10"
oTextBox.TextFrame.TextRange = "Work Order number " & vbCrLf & vbCrLf & "
TESTFY"

If iPage <> iTotalPages Then
   oBrowser.Target = wdBrowsePage
   oBrowser.Next
End If

Next iPage

objWord.Visible = True

objWord.Quit wdDoNotSaveChanges

Regards,
Luke Skywalker

> Hi all,
>
[quoted text clipped - 56 lines]
> ---
> Message posted from http://www.ExcelForum.com/

Rate this thread:






 
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.