|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Auto-increment text form fields in MS Word
I have a Word document with four forms on a page. Each of the four forms has a text form field which I want to have consecutive numbers in. So if I print 10 sheets the forms will be numbered 1 through 40.
Is it possible to attach a macro to each of these fields to increment each of them by one every time a new page is printed. It would be nice to have a window opening to ask which number to start at Thanks in advance Geoff |
|
#2
|
||||
|
||||
|
include the increment inside the printing function.
after printing add 1 to a variable. variable = variable + 1 then text1 = variable |
|
#3
|
|||
|
|||
|
Hi Zynder,
Thanks for the steer. I now realise that I can set the text forms as a calculation with expressions "=variable", "=variable+1" etc. I now need to write a bit of VB, which is where the problem comes! I've created a module with Code:
Sub SetupConsecNos()
Dim variable As Integer
Text1 = variable
For variable = 0 To 500
variable = variable + 1
Next variable
End Sub
and then another module to actually print the document Code:
Sub PrintConsecNos()
Call SetupConsecNos
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=2
End Sub
Which doesn't work Is this the sort of thing you meant? Thanks for your help! |
|
#4
|
||||
|
||||
|
Nope. Use one function for both.
Code:
Sub PrintConsecNos()
Dim intCount as Integer
Call SetupConsecNos
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=2
'increment by 1
intCount = intCount + 1
'put the value to text1
Text1 = intCount
End Sub
|
|
#5
|
|||
|
|||
|
Hi Zynder,
I'm a little confused now! I now have a module with the following Code:
Sub SetUpConsecNos()
Dim variable As Integer
Text1 = variable
For variable = 0 To 500
variable = variable + 1
Next variable
End Sub
Sub PrintConsecNos()
Dim intCount As Integer
Call SetUpConsecNos
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1
'increment by 1
intCount = intCount + 4
'put the value to text1
Text1 = intCount
End Sub
and the Text Form Field Options set to Type: Calculation Expression: =intCount Maximum Length: 4 Number format: 0 I note the line Text1 = intCount but presume that the Text Form Field Options should be set in some way as well. As there are four Text Form Fields on each page and I am likely to have to print 100 pages I have changed the line intCount = inCount + 1 to intCount = intCount + 4 Many thanks for your comments so far. Regards Geoff |
|
#6
|
||||
|
||||
|
You are running a For Loop on your SetUpConsecNos Sub, which wont do any good. Replace your code with my code on post #4.
|
|
#7
|
|||
|
|||
|
Hi Zynder,
I now have the following code Code:
Sub SetUpConsecNos()
Dim intCount As Integer
Text1 = intCount
For intCount = 0 To 500
intCount = intCount + 1
Next intCount
End Sub
Sub PrintConsecNos()
Dim intCount As Integer
Call SetUpConsecNos
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=2
'increment by 1
intCount = intCount + 4
'put the value to text1
Text1 = intCount
End Sub
This runs and shows zeros but does not increment the numbers if I print two pages. Should I have the Text Form Field Options for Text1 set to Type: Calculation Expression: = intCount Maximum Length: 4 Number format: 0 and the Text Form Field Options for Text2 set to Type: Calculation Expression: = intCount + 1 Maximum Length: 4 Number format: 0 etc. I'm obviously being a bit dim and not understanding what you mean ![]() |
|
#8
|
||||
|
||||
|
Code:
Sub SetUpConsecNos()
Dim intCount As Integer
Text1 = intCount
For intCount = 0 To 500
intCount = intCount + 1
Next intCount
End Sub
Sub PrintConsecNos()
Dim intCount As Integer
Call SetUpConsecNos
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=2
'increment by 1
intCount = intCount + 4
'put the value to text1
Text1 = intCount
End Sub
See the bold fonts? Delete it or remove it. Exterminate that code. Just get rid of it. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Auto-increment text form fields in MS Word |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|