Inserting Text From Text File (*.ini)

D

Diamonds_Mine

Currently the code below is used to insert a *.jpg image into my document by
using a field from an *.ini file ("addresscolor"); the jpg image has
addresses and phone numbers:

strOfficeFile = "c:\Program Files\Microsoft
Office\Templates\HHSystemFiles\address.ini"
strOfficeName = pOffice
logofilename = System.PrivateProfileString(strOfficeFile, strOfficeName,
"LogoColor")
addressfilename = System.PrivateProfileString(strOfficeFile,
strOfficeName, "AddressColor")

ActiveDocument.Bookmarks("Address").Select
Selection.InlineShapes.AddPicture FileName:="c:\Program Files\Microsoft
Office\Templates\SystemFiles\" & addressfilename, _
LinkToFile:=False, SaveWithDocument:=True

I no longer want to use the *.jpg images to insert the addresses and need to
insert lines of text from the *.ini file for example:

[Washington]
Line1=123 Maple Lane
Line2=Washington, DC 20001
Line3=202.555.1212

[Virginia]
Line1=456 Magnolia Way
Line2=Arlington, VA 20777
Line3=703.555.1313

How can I accomplish this? Thank you in advance for your responses.
 
F

Fumei2 via OfficeKB.com

Given

[Washington]
Line1=123 Maple Lane
Line2=Washington, DC 20001
Line3=202.555.1212

in a file address.ini at the loaction below:

Sub GetAddress()
Dim strOfficeFile
Dim strFullInfo As String

strOfficeFile = "c:\Gerry\address.ini"

strFullInfo = "Washington" & vbCrLf & _
System.PrivateProfileString(strOfficeFile, "Washington", "Line1") & _
vbCrLf & _
System.PrivateProfileString(strOfficeFile, "Washington", "Line2") & _
vbCrLf & _
System.PrivateProfileString(strOfficeFile, "Washington", "Line3")

MsgBox strFullInfo
End Sub

would display:

Washington
123 Maple Lane
Washington, DC 20001
202.555.1212


Diamonds_Mine said:
Currently the code below is used to insert a *.jpg image into my document by
using a field from an *.ini file ("addresscolor"); the jpg image has
addresses and phone numbers:

strOfficeFile = "c:\Program Files\Microsoft
Office\Templates\HHSystemFiles\address.ini"
strOfficeName = pOffice
logofilename = System.PrivateProfileString(strOfficeFile, strOfficeName,
"LogoColor")
addressfilename = System.PrivateProfileString(strOfficeFile,
strOfficeName, "AddressColor")

ActiveDocument.Bookmarks("Address").Select
Selection.InlineShapes.AddPicture FileName:="c:\Program Files\Microsoft
Office\Templates\SystemFiles\" & addressfilename, _
LinkToFile:=False, SaveWithDocument:=True

I no longer want to use the *.jpg images to insert the addresses and need to
insert lines of text from the *.ini file for example:

[Washington]
Line1=123 Maple Lane
Line2=Washington, DC 20001
Line3=202.555.1212

[Virginia]
Line1=456 Magnolia Way
Line2=Arlington, VA 20777
Line3=703.555.1313

How can I accomplish this? Thank you in advance for your responses.
 
Top