Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing A Text Box Within Word

Status
Not open for further replies.

ChrisBelzona

Programmer
Oct 25, 2000
137
GB
I have two text boxes on the first page of a word template for Name and Company.

I would like to display the values the user enters on each page footer, I'm an access programmer and know little about word, so any help would be great.

Regards

Chris
 
something like this:

Sub AutoExec()
Dim lWiewVal As Long, sMyString As String

lWiewVal = ActiveWindow.ActivePane.View.SeekView

'add bookmark to store the current pos
ActiveDocument.Bookmarks.Add Name:="temp"

'get the text of page header into sMyString
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
sMyString = Selection.Text
'set TBox2 text to headers val
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Application.ActiveDocument.Shapes("Text Box 2").Select
Selection.Text = sMyString

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
sMyString = Selection.Text

ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Application.ActiveDocument.Shapes("Text Box 3").Select
Selection.Text = sMyString

'go to the starting pos
ActiveDocument.Bookmarks("temp").Select
ActiveDocument.Bookmarks("temp").Delete
End Sub

i hope it helps
ide
 
ide

Thanks for your quick response, I have tried the code however my text fields are not in the header they are just on the page one, in access vba I would use an after update event on the second text box then action my code. Is this how the above code works? also Does it assume the fields are in the header?

Thanks Again

Chris Russell
 
i was confused, sorry :) the foregoing code pastes the header and the footer into two textboxes.

I have two idea:
1.:
you have the two text boxes from Drawing toolbar ("Text Box 1" and "Text Box 2"); insert into a command button to run this sub (has no any events)

Sub fnChangeFooter()
Dim lWiewVal As Long, sMyString As String
Application.ScreenUpdating = False
lWiewVal = ActiveWindow.ActivePane.View.Type
ActiveWindow.ActivePane.View.Type = wdPrintView

'add bookmark to store the current pos
ActiveDocument.Bookmarks.Add Name:="temp"

ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Application.ActiveDocument.Shapes("Text Box 7").Select

Selection.ShapeRange.TextFrame.TextRange.Select
sMyString = Selection.Text

Application.ActiveDocument.Shapes("Text Box 9").Select
Selection.ShapeRange.TextFrame.TextRange.Select

sMyString = sMyString & Selection.Text

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
Selection.Text = sMyString

ActiveWindow.ActivePane.View.Type = lWiewVal
'go to the starting pos
ActiveDocument.Bookmarks("temp").Select
ActiveDocument.Bookmarks("temp").Delete
Application.ScreenUpdating = True
End Sub

*******************************************************
2.:
textbox of Control toolbox (Change event).
the code of ThisDocument (not in a module)

Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long

Private Sub TextBox2_Change()
sbChangeFooter
End Sub
Private Sub TextBox1_Change()
sbChangeFooter
End Sub

Sub sbChangeFooter()
Dim lViewVal As Long, sMyString As String

'lock screenupdating
LockWindowUpdate GetDesktopWindow
LockWindowUpdate FindWindow("OpusApp", "")

'add bookmark to store the current pos
ActiveDocument.Bookmarks.Add Name:="temp"
sMyString = Me.TextBox1.Text & vbCrLf & Me.TextBox3.Text
With ActiveDocument.ActiveWindow.View
lViewVal = .Type
.Type = wdPrintView
.SeekView = wdSeekCurrentPageFooter
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
Selection.Text = sMyString
.Type = lViewVal
End With
'go to the starting pos
ActiveDocument.Bookmarks("temp").Select
ActiveDocument.Bookmarks("temp").Delete

' Enable ScreenUpdating
LockWindowUpdate (0)
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top