Hello All,
What I am trying to do is simular to a mail merge. I want to pull data from a excel sheet and push the data to a word document. For each record create a new word document. I have it working with a excel to excel document but I am not sure to to push the data from excel to word and then save the word for each record. (if this is making any sense)
Here is the code I started with:
Code:
Sub Create_SteFiles()
Dim SiteName, SaveAsName As String
Dim SiteID, LAT, LON, StreetAddress, City, State, ZIPCode As String
Dim CounterRange, MaxValueRange As Integer
MaxValueRange = 69
For CounterRange = 2 To MaxValueRange
Workbooks.Open Filename:="C:\Site Survey Form.xls"
'****Clears out all the variable Data for the next Cycle *****
SiteName = ""
SiteID = ""
LAT = ""
LON = ""
StreetAddress = ""
City = ""
State = ""
ZIPCode = ""
SaveAsName = ""
TransferString = ""
'*****************************************************
Windows("HI Market Tracker.xls").Activate
'************Pull Data From the spreadsheet Here ******
SiteName = Range("A" + Trim(Str(CounterRange))).Value
SiteID = Range("B" + Trim(Str(CounterRange))).Value
LAT = Range("F" + Trim(Str(CounterRange))).Value
LON = Range("G" + Trim(Str(CounterRange))).Value
StreetAddress = Range("K" + Trim(Str(CounterRange))).Value
City = Range("L" + Trim(Str(CounterRange))).Value
State = Range("M" + Trim(Str(CounterRange))).Value
ZIPCode = Range("N" + Trim(Str(CounterRange))).Value
'*****************************************************
Windows("Site Survey Form.xls").Activate
'************Push Data to the spreadsheet Here ******
Range("F10").Value = Trim(SiteName)
Range("C10").Value = Trim(SiteID)
Range("F13").Value = Trim(LAT)
Range("H13").Value = Trim(LON)
Range("C12").Value = Trim(StreetAddress)
Range("H12").Value = Trim(City)
Range("J12").Value = Trim(State)
Range("C13").Value = Trim(ZIPCode)
'*****************************************************
SaveAsName = "C:\_LC_Sites\" + SiteID + ".xls"
ActiveWorkbook.SaveAs Filename:=SaveAsName
ActiveWorkbook.Close
'Workbooks.Open Filename:=SaveAsName
'Windows(Sitename + ".xls").Activate
'Range("C8").Value = Sitename
'ActiveWorkbook.Save
Next CounterRange
'ActiveWorkbook.SaveAs Filename:=SaveAsName
End Sub
Any Ideas
Thanks!!
What I am trying to do is simular to a mail merge. I want to pull data from a excel sheet and push the data to a word document. For each record create a new word document. I have it working with a excel to excel document but I am not sure to to push the data from excel to word and then save the word for each record. (if this is making any sense)
Here is the code I started with:
Code:
Sub Create_SteFiles()
Dim SiteName, SaveAsName As String
Dim SiteID, LAT, LON, StreetAddress, City, State, ZIPCode As String
Dim CounterRange, MaxValueRange As Integer
MaxValueRange = 69
For CounterRange = 2 To MaxValueRange
Workbooks.Open Filename:="C:\Site Survey Form.xls"
'****Clears out all the variable Data for the next Cycle *****
SiteName = ""
SiteID = ""
LAT = ""
LON = ""
StreetAddress = ""
City = ""
State = ""
ZIPCode = ""
SaveAsName = ""
TransferString = ""
'*****************************************************
Windows("HI Market Tracker.xls").Activate
'************Pull Data From the spreadsheet Here ******
SiteName = Range("A" + Trim(Str(CounterRange))).Value
SiteID = Range("B" + Trim(Str(CounterRange))).Value
LAT = Range("F" + Trim(Str(CounterRange))).Value
LON = Range("G" + Trim(Str(CounterRange))).Value
StreetAddress = Range("K" + Trim(Str(CounterRange))).Value
City = Range("L" + Trim(Str(CounterRange))).Value
State = Range("M" + Trim(Str(CounterRange))).Value
ZIPCode = Range("N" + Trim(Str(CounterRange))).Value
'*****************************************************
Windows("Site Survey Form.xls").Activate
'************Push Data to the spreadsheet Here ******
Range("F10").Value = Trim(SiteName)
Range("C10").Value = Trim(SiteID)
Range("F13").Value = Trim(LAT)
Range("H13").Value = Trim(LON)
Range("C12").Value = Trim(StreetAddress)
Range("H12").Value = Trim(City)
Range("J12").Value = Trim(State)
Range("C13").Value = Trim(ZIPCode)
'*****************************************************
SaveAsName = "C:\_LC_Sites\" + SiteID + ".xls"
ActiveWorkbook.SaveAs Filename:=SaveAsName
ActiveWorkbook.Close
'Workbooks.Open Filename:=SaveAsName
'Windows(Sitename + ".xls").Activate
'Range("C8").Value = Sitename
'ActiveWorkbook.Save
Next CounterRange
'ActiveWorkbook.SaveAs Filename:=SaveAsName
End Sub
Any Ideas
Thanks!!