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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

merging data to fields from an ini file 1

Status
Not open for further replies.

colinmitton

Technical User
Feb 24, 2005
190
GB
I need to be able to open a letter (from a standard template) and from a ini file call back up things like reference numbers / intials?

I'm not sure if thats the best way of doing it (or explaining it) but I want to set up templates where everyone picks up one template and it customises there reference from a file on there computer?

Hope this makes sense!

Colin
 
An .ini file might work, but for the simple kinds of things you are describing, can't you just use the user information fields already built into Word?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Thanks for the quick responce,

Steve, I'm not sure how to use the information fields already there in Word! and also it would mean me having to change everyone as they current are all of a ghost image. If you could give me any hints on either looking at the user information to auto insert it to the docuemtn or read a ini file that would be great.

Skip, I'm just getting to grips with style and I'm unsure how I can achive it with them, also I have tried the macro route but it would involve me re-writing it for each user so I can add / change intials. I thought if I could have a single document that references a file in a common area, I then can deploy the relevent files / structure and for the future just maintain one template. (if that makes sense).

If anyone could let me know how to insert the data in to the template that would be great as I'm a bit stuck now.

Thanks very much

Colin
 
Tools->Options->User Information tab

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 



"...but it would involve me re-writing it for each user so I can add / change intials..."

You can have ONE macro for MULTIPLE users. Please post the macro that you have and explain the USER specific data and what needs to change.

Skip,

[glasses] [red][/red]
[tongue]
 
Okay,

The code I have so far is like this :

Sub getlettchgint()
'
' getlettchgint Macro
' Macro recorded 11/14/2006 by cjm
'
Documents.Add Template:="K:\Documents\CJMitton\LETTERHEAD.dot", _
NewTemplate:=False, DocumentType:=0
Selection.MoveRight Unit:=wdCharacter, Count:=10
Selection.TypeBackspace
Selection.TypeText Text:="CJM1"
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.TypeBackspace
Selection.TypeText Text:="CJM2"
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
End Sub

It opens a template then manually moves to where the data needs to be changed in the template. The template is currently in tables for the address, ref, date, etc.

the part I need to chaneg look at bit like below!

Our Ref: *.*.*
Your Ref: *
Date: *

Where * are is the start of a diffent cell in the table. I need to change the *.*.* to the relevent reference, the first * needs to be one set of intials the second a different set of initials the final * needs to stay so like my example :

Our Ref: CJM1.CJM2.*

this means that CJM1 and CJM2 would need to be variables for each person with the template.

Hope this make senses.

Colin
 


So the places that need to be filles are all in a TABLE?

Is there only ONE table in the document?

What is the cell reference for each element?

How many different users?

Do you have a table of the UserID and the values associated?

Are the UserID's in a network?

Skip,

[glasses] [red][/red]
[tongue]
 
Not sure if an INI files the way to go either as I don't completely understand your question (Answer Skips questions for better help). But you asked about an INI so here's an example to play with....

Code:
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
    (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, _
    ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" _
    (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, _
    ByVal lpFileName As String) As Long

Sub Main()
    Dim sUserName As String * 30
    Dim sUserId As String * 30

    If GetPrivateProfileString("UserInfo", "UserName", "Default", sUserName, 30, "c:\" & Environ("UserName") & ".ini") = 7 Then
        sUserName = InputBox("Enter User Name")
        RC = WritePrivateProfileString("UserInfo", "UserName", sUserName, "c:\" & Environ("UserName") & ".ini")
    End If

    If GetPrivateProfileString("UserInfo", "UserId", "Default", sUserId, 30, "c:\" & Environ("UserName") & ".ini") = 7 Then
        sUserId = InputBox("Enter User Id")
        RC = WritePrivateProfileString("UserInfo", "UserId", sUserId, "c:\" & Environ("UserName") & ".ini")
    End If

    MsgBox "User Name is " & sUserName
    MsgBox "User Id is " & sUserId

End Sub

open c:\YourUserName.ini in notepad and you'll see


[UserInfo]
UserName= Whatever you entered
UserId= Whatever you entered

Each ini file can have multiple [Sections] with multiple Elements
very usful to store prefrences for individual users if you use something like.

[SystemPrefs]
KeyboardMap = SomeKey.ekm
SomeCustomSetting = Color Red

[EmployeeInfo]
EmployeeNum = 87654321
Note1 = Modified per client request
Note2 = ect. ect.

To better understand the API call and it's return check out




[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.
 
Firstly Thanks to everyone!

I would like to answer skips questions first:

So the places that need to be filles are all in a TABLE?
Yep, they are in a table

Is there only ONE table in the document?
The Template docuemtn only has the one table in at creation but could have more after initially being opened, as you would well guess.

What is the cell reference for each element?
I'm not sure if there is some hidden reference for the cells with-in word but to use excel row and column references and a description:
The first three the rows have two columns:
1A : has Our Ref: in, 1B : Has *.*.* in, (of which the first * needs to be a variable and the second * is also needs to be a variable for the relevent initials)
2A : has Your Ref: in, 2B : Has * in,
3A : has Date: in, 3B : Has the date in *(which auto inserts)
4A : Is a single cell (above merged together) nothing in
5A : Is a single cell again but enough room for a full address

How many different users?
About 50

Do you have a table of the UserID and the values associated?
Not yet

Are the UserID's in a network?
Yep.. in active directory on a w2k3 AD

I Would also like to clear up the whole initial / reference thing! I work for a law firm (please dont stop giving me help :) ) Our reference is made up of the typists intials and full stop then the fee-earners intials then a full stop and finishing with the client number full stop then matter number so it looks like :
ABD.XYZ.123456.1
The ABC and XYZ need to be the entered from the INI file or another place (active directory) on opening. Like a mailmerge? if that make sense.
I need to create one template for 50 people that automatically personalises for them. To save me doing it 50 times! and if I make a change to the template letter doing it another 50 times.

If you need a copy of my letter template or if theres somewhere I could Post it I can do that if it would help?

MrMilson...
I'll have a look in to your code and give it a go.

Has anyone got any ideas on getting the information in to word when the template opens? Sorry about this but I did say I'm new to VBA and the best I have done is play with the code from a recorded macro! or over 15 years ago did some programming in C, Cobol, Pascal!! so not exactly fresh :)

Thanks again folks
Colin
 
Colin

Assume that individual typists may do typing for different fee earners, who may in turn do work for different clients. From your description of the reference scheme, the only things you can reliably auto-populate are the typist's initials and the date. Which you can do with fields, rather than a macro.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Steve,

We Generally have on typist working for one fee-earner (we're an old 'traditional' law firm) but I will look in to fields (I have never used these before) I guess you can link them to an outside source of some sort. I will look in to it and let you know.

Thanks for the tip.

Colin
 
AFIAK you can't link them to an outside source. The value of the UserInitials field is what you set from the options menu, and is per user (typist). I just set mine to SSS.XYZ and it works fine.

Haven't tried it in a template. Does anyone know what happens to fields like this when you open a new document based on a template? Do they get updated automatically?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
I have given it a go and it seems the fields auto update from the template when you create a new document!

The next part is to reference a INI file or Active Directory, if this can be done? It would make things a little more felixable for what I want to do in the future.

Thanks Again

Colin

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top