Using data from an .ini file in Word

A

adam

Hello all. I'm new to this group but I really hope I can get some help.

I need to add data from an .ini file and insert in the document.

I've tried this:

Content of the file User.ini:

[User]
Name = my name
Mail = (e-mail address removed)
Fax = No fax
Tel = 0706 996106
Company= Freeducation

This is my VBA code:

Sub IniValueAtBookmark()
Dim sName As String
Dim sMail As String
Dim sFax As String
Dim sTel As String
Dim sCompany As String


'Get the values
sName = System.PrivateProfileString("C:\Documents and
Settings\Adam\Mina dokument\User.ini", "User", "Name")
sMail = System.PrivateProfileString("C:\Documents and
Settings\Adam\Mina dokument\User.ini", "User", "Mail")
sFax = System.PrivateProfileString("C:\Documents and
Settings\Adam\Mina dokument\User.ini", "User", "Fax")
sTel = System.PrivateProfileString("C:\Documents and
Settings\Adam\Mina dokument\User.ini", "User", "Tel")
sCompany = System.PrivateProfileString("C:\Documents and
Settings\Adam\Mina dokument\User.ini", "User", "Company")

End Sub

I see the value of theese expressions in the "Local" window in VBA so
this far I figure I'm right.
How do place theese values into my document? Can I let Normal.dot run
the macro and then place the values into other documents with a field
or do I have to run the macro on each document?
I've tried half a day but just go into dead ends.

What I'm trying to acheive is to have a set of standard Word templates
filling in different userdata for each user in a big company.
I tried using the Custom properties that you can set in word but they
would follow the document, not the user, right?
Hope this wasn't too messy.

Cheers
Adam, Sweden
 
D

Doug Robbins - Word MVP

Where do you want the data to appear in the document?

I would advise that you create templates other than the normal.dot template
for your purposes. You could put code into an autonew() macro in a template
that you save in the Word\Startup folder that created a set of variables in
any new document created from any template to contain the information that
you are extracting from the ini file. In those templates where you want the
information to appear, in documents created from them, you would have
{DOCVARIABLE varname } fields to display the information. This would save
having to create an autonew macro in each template. The macro in the addin
(the template in the Word\Startup folder) should also include code to update
the fields in the documents.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

adam

Where do you want the data to appear in the document?

They will be placed in a table on the top of page 1 in the template.
It's a letterhead (but not in the header and footer)

I would advise that you create templates other than the normal.dot template
for your purposes. ....., in documents created from them, you would have
{DOCVARIABLE varname } fields to display the information.

I will create the autonew() macro and put it in the startup folder. But
how do I use the DOCVARIABLE. Do I need to add code to my macro to
create variables that DOCVARIABLE can use. When I make a field like
DOCVARIABLE sTel I just get a blank when I toggle fieldcodes.

Thank You for the help, you are really putting me back on track.

Adam
 
D

Doug Robbins - Word MVP

You put the docvariable fields in the template. When a new document is
created from the template, it will contain those fields and when the autonew
macro creates the variables in the document and updates the fields (the
docvariable fields) they will display the information that is stored in the
variables.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

Adam

Thanks Doug!
I've got it all togeater now.
I appreciate your help a lot, thougt I was going crazy there for a
while!

Adam
 

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