save some values to normal.dot

C

Co

Hi All,

I Have a macro that can run code with different settings.
Now I was wondering if it is possible to save these settings somewhere
in the normal.dot.
I need to save the following:

pSubject, pNumber, pDate, pChar, pNOC, pSource.

These fields for multiple settings.
I can then open my form, choose a Source and automatically would have
the valules
of the fields filled out on my form

Marco
 
G

George Lee

Rather than to fuss with modifying the template, an easy way would be to use
ini files. Word provides PrivateProfileString to create and read from this.
To make it more transparent, rewrite ReadIni and CreateIni as the templates
autos AutoExec and AutoExit so they run automatically when the template is
opened and closed respectively.

Option Explicit

Dim subjectString As String
Dim numberString As String
Dim dateString As String

Public Sub FirstTimeCreate()
On Error GoTo MyErrorHandler
'Your application would actually supply these values in a real world case.
subjectString = "The Subject"
numberString = "A number"
dateString = "10/1/2008"
Exit Sub
MyErrorHandler:
MsgBox "FirstTimeCreate" & vbCrLf & vbCrLf & "Err = " & Err.Number &
vbCrLf & "Description: " & Err.Description
End Sub

Public Sub CreateIni()
On Error GoTo MyErrorHandler
System.PrivateProfileString("MyGlobalSettings.ini", "LastSettings",
"pSubject") = subjectString
System.PrivateProfileString("MyGlobalSettings.ini", "LastSettings",
"pNumber") = numberString
System.PrivateProfileString("MyGlobalSettings.ini", "LastSettings",
"pDate") = dateString
Exit Sub
MyErrorHandler:
MsgBox "CreateIni" & vbCrLf & vbCrLf & "Err = " & Err.Number & vbCrLf &
"Description: " & Err.Description
End Sub

Public Sub ReadIni()
On Error GoTo MyErrorHandler
subjectString = System.PrivateProfileString("MyGlobalSettings.ini",
"LastSettings", "pSubject")
numberString = System.PrivateProfileString("MyGlobalSettings.ini",
"LastSettings", "pNumber")
dateString = System.PrivateProfileString("MyGlobalSettings.ini",
"LastSettings", "pDate")
Exit Sub
MyErrorHandler:
MsgBox "ReadIni" & vbCrLf & vbCrLf & "Err = " & Err.Number & vbCrLf &
"Description: " & Err.Description
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top