O
Ollie
My business is fond of reorganistations, and recreating corporate templates
each time is becoming a chore. Therefore I want to have a document that I
can design to corporate standards that will collect information from a user
and use that to save a template for future use. The user details simply
round of the particulars for the template. I have a form with some code
that collects the information, writes it to the currennt document in the
required format and then saves the document as a template fior future use.
The code looks like this:
Sub AutoOpen()
'
' This macro collects some user information and creates a template based on
it.
'
Dim strYourName As String
Dim strJobTitle As String
Dim strMyFileName As String
Dim lngPosSpaceChar As Long
Dim strAppUserName As String
'Get the user's name. Use Application Property if not User ID, else collect
name from user
'Look for space char in Application Property as criteria
strAppUserName = Application.UserName
If InStr(1, strAppUserName, " ") = 0 Then
strYourName = InputBox("Please enter your name.")
Else: strYourName = Application.UserName
End If
'Get user's job
strJobTitle = InputBox("Please enter your job title.")
'Write the data to the document
With Selection
.GoTo what:=wdGoToBookmark, Name:="sender"
.TypeText Text:=strYourName
.GoTo what:=wdGoToBookmark, Name:="job"
.TypeText Text:=strJobTitle
.GoTo what:=wdGoToBookmark, Name:="signature"
.TypeText Text:=strYourName
.GoTo what:=wdGoToBookmark, Name:="start"
End With
'Find user's surname and use as file name
lngPosSpaceChar = InStr(1, strYourName, " ")
strMyFileName = Right(strYourName, Len(strYourName) - lngPosSpaceChar)
'Save file as template
ActiveDocument.SaveAs _
FileName:="C:\Documents and Settings\ok23378\Application
Data\Microsoft\Templates\" & _
strMyFileName & ".dot", fileFormat:=wdFormatTemplate
'Alert user
MsgBox ("You now have a personal template." & vbCr & vbCr & "Access it
from File | New")
End Sub
All well and good so far. But the document uses a table to position some
elements on a page, and new documents created with the template the code
creates have the insertion point in the first field of the table. That
isn't where I need it - it needs to be at the point where the user starts to
enter text, identified by a bookmark. I can't see a way to do this.
Any help will be much appreciated.
Ollie
each time is becoming a chore. Therefore I want to have a document that I
can design to corporate standards that will collect information from a user
and use that to save a template for future use. The user details simply
round of the particulars for the template. I have a form with some code
that collects the information, writes it to the currennt document in the
required format and then saves the document as a template fior future use.
The code looks like this:
Sub AutoOpen()
'
' This macro collects some user information and creates a template based on
it.
'
Dim strYourName As String
Dim strJobTitle As String
Dim strMyFileName As String
Dim lngPosSpaceChar As Long
Dim strAppUserName As String
'Get the user's name. Use Application Property if not User ID, else collect
name from user
'Look for space char in Application Property as criteria
strAppUserName = Application.UserName
If InStr(1, strAppUserName, " ") = 0 Then
strYourName = InputBox("Please enter your name.")
Else: strYourName = Application.UserName
End If
'Get user's job
strJobTitle = InputBox("Please enter your job title.")
'Write the data to the document
With Selection
.GoTo what:=wdGoToBookmark, Name:="sender"
.TypeText Text:=strYourName
.GoTo what:=wdGoToBookmark, Name:="job"
.TypeText Text:=strJobTitle
.GoTo what:=wdGoToBookmark, Name:="signature"
.TypeText Text:=strYourName
.GoTo what:=wdGoToBookmark, Name:="start"
End With
'Find user's surname and use as file name
lngPosSpaceChar = InStr(1, strYourName, " ")
strMyFileName = Right(strYourName, Len(strYourName) - lngPosSpaceChar)
'Save file as template
ActiveDocument.SaveAs _
FileName:="C:\Documents and Settings\ok23378\Application
Data\Microsoft\Templates\" & _
strMyFileName & ".dot", fileFormat:=wdFormatTemplate
'Alert user
MsgBox ("You now have a personal template." & vbCr & vbCr & "Access it
from File | New")
End Sub
All well and good so far. But the document uses a table to position some
elements on a page, and new documents created with the template the code
creates have the insertion point in the first field of the table. That
isn't where I need it - it needs to be at the point where the user starts to
enter text, identified by a bookmark. I can't see a way to do this.
Any help will be much appreciated.
Ollie