PDA

View Full Version : form fields in excel



tammytutone
07-23-2008, 12:55 PM
I created a form letter in Excel 2007 that has a lot of calculations in it. Now, I want to know if there is a way to have the "text" cells of the letter be populated with the user's name, address, phone number and email address. I was thinking of something like form fields in Word. Can this be done? By the way, I am not a regular Excel user.

mdmackillop
07-23-2008, 01:01 PM
I'm sure we can do this. Where is your data stored? Can you post a sample?

tammytutone
07-23-2008, 02:37 PM
When I create form letters in Word, I have a macro that pulls all the user info from a data.ini file located in the user's home drive, so that no matter what machine they are working at, their unique information will follow them. In the document, I have text form fields with bookmark names that correspond to the fields in the data.ini file. It looks like this:

data.ini file:

[Info]
Username=JANE SMITH
Usertitle=Frustrated Employee
UserAddress=1111 WEST FIRST STREET, 11th FLOOR, CITY, STATE 11111-1111
Userphone=(111) 111-1111
Useremail=jane.smith@agency.gov
UserFax=(111) 111-2222

The macro in the Word form looks like this:
Sub letterhead()
'
' Letterhead Macro
'
'Declare variables
Dim strFile As String
Dim strUsername As String
Dim strUsertitle As String
Dim strUseraddress As String
Dim strUserphone As String
Dim strUseremail As String
strFile = "H:\Data.ini"
strUsername = System.PrivateProfileString(strFile, "Info", "Username")
strUsertitle = System.PrivateProfileString(strFile, "Info", "Usertitle")
strUseraddress = System.PrivateProfileString(strFile, "Info", "Useraddress")
strUserphone = System.PrivateProfileString(strFile, "Info", "Userphone")
strUseremail = System.PrivateProfileString(strFile, "Info", "Useremail")

ActiveDocument.FormFields("Username").Result = strUsername
ActiveDocument.FormFields("Usertitle").Result = strUsertitle
ActiveDocument.FormFields("Useraddress").Result = strUseraddress
ActiveDocument.FormFields("Userphone").Result = strUserphone
ActiveDocument.FormFields("Useremail").Result = strUseremail
Selection.GoTo What:=wdGoToBookmark, Name:="start"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
ActiveWindow.View.ShowBookmarks = False

End Sub


I wanted to try the same thing in Excel, but I can't figure out how to put the text form fields in a cell.