Originally Posted by
gmayor
Post the code so we can see what you are doing.
The code is simple,
Sub TP5_0()
'
' TP5_0 Macro
'
'
Dim contents1 As String
contents1 = ActiveDocument.FormFields("Number3").Result
Value1 = Val(contents1)
If ((Value1 > 5.1) Or (Value1 < 4.9)) And Not (contents1 = "---.---") Then Beep: MsgBox ("Out of Tolerance")
End Sub
Sub SelectionScrollIntoMiddleOfView()
Dim pLeft As Long
Dim pTop As Long, lTop As Long, wTop As Long
Dim pWidth As Long
Dim pHeight As Long, wHeight As Long
Dim Direction As Integer
wHeight = PixelsToPoints(ActiveWindow.Height, True)
ActiveWindow.GetPoint pLeft, wTop, pWidth, pHeight, ActiveWindow
ActiveWindow.GetPoint pLeft, pTop, pWidth, pHeight, Selection.Range
Direction = Sgn((pTop + pHeight / 2) - (wTop + wHeight / 2))
Do While Sgn((pTop + pHeight / 2) - (wTop + wHeight / 2)) = Direction And (lTop <> pTop)
ActiveWindow.SmallScroll Direction
lTop = pTop
ActiveWindow.GetPoint pLeft, pTop, pWidth, pHeight, Selection.Range
Loop
End Sub
TP5_0() checks the tolerance on text input form fields. SelectionScrollIntoMiddleOfView() centers the active form field in the middle of the screen. I place SelectionScrollIntoMiddleOfView() in the Run macro on/Entry in the Form Field Options box when I want to place the field in center screen. I place TP5_0() in the Run macro on/Exit in the Text Form Field Option box of the text box I wish to check tolerances. None of this changes the document itself in anyway. So I don't have to unprotect the document and re-protect the document.
The file name is "Testing macro distribution" and the code is in project ( Testing macro distribution). There is no code in Normal.
The first thing I want to do is be able to open a new document based on this template and run the code on the document as well. The second thing I want to do is be able to publish the template so that anyone at my company will be able to use this template to create new documents which will also run the code. I do appreciate any help given in this regard.
So far the only thing that works is the template, and it works also when I email the template to myself.
I think I need to understand more about where to place code, in project or in Normal, and why.