 |
 |

09-10-2003, 01:40 PM
|
 |
Junior Contributor
|
|
Join Date: Mar 2003
Location: PA, USA
Posts: 303
|
|
URGENT! Mail Merge w/VB
|
Hey:
When doing a Cover Letter (form letter) mail merge, I wanna save each page as it's own file. Is there a way to Automate this w/VB?
The scenario is:
Each row in Excel fills up 1 letter (some may be 1 p., some 2, depending on the row of Data)
I'm using Excel as my Source...
If anyone has an idea... this is urgent, as I need to start stuffing envelopes tomorrow morning!
I'm well versed in VB for Excel, but I know oh so little about MS Word.
Thanks for you help!
--Dodd
|
__________________
"Princekimmer Skimple... Primable Skimster... I, I found something!!!!"
--Ralph Wiggum
|

09-11-2003, 01:33 AM
|
 |
Junior Contributor
|
|
Join Date: Jul 2003
Location: Somerset, England
Posts: 234
|
|
|
As a suggestion:
Drive it from word, pick up the appropriate excel row and save the word doc, close the doc and start a new one picking up the next excel row.
|
__________________
Chris Lawery
|

09-11-2003, 07:27 AM
|
 |
Junior Contributor
|
|
Join Date: Mar 2003
Location: PA, USA
Posts: 303
|
|
I need more specifics...
Quote: Originally Posted by Crittar As a suggestion:
Drive it from word, pick up the appropriate excel row and save the word doc, close the doc and start a new one picking up the next excel row.
Hey: Would you happen to have the code for finding the row in Excel? I know so little of VB for Word... all I've been able to identify the MailMerge Field from Word VB is the Title (.Name) of the Merge Field (The Column Header in Excel), not the actual .Value or .Text of the Cell in Question. (I can't find anything of that sort in Word's Object Browser and I don't know how to call such a thing from Excel's Library in Word VB)
As you can see, I'm quite lost...
--Dodd
|
__________________
"Princekimmer Skimple... Primable Skimster... I, I found something!!!!"
--Ralph Wiggum
|

09-12-2003, 01:37 AM
|
 |
Junior Contributor
|
|
Join Date: Jul 2003
Location: Somerset, England
Posts: 234
|
|
Code:
Sub Expenses()
'
' Expenses Macro
' Macro created 14/08/2003 by Chris Lawery
'
Dim MyShortMonth, MyShtId, MyYear, MyShortDate
' Define appropriate objects to access the sheet.
Dim MyXl As Object, MyBook As Object, MySheet As Object, MyRange As Object
Load UserForm2
UserForm2.Show
MyShortMonth = Left(MyMonth, 3)
MyYear = Year(Now)
If MyShortMonth = "Jan" Then
MyYear = MyYear - 1
End If
MyShtId = MyShortMonth & " " & MyYear
' Open excel, error code is to handle already open or not.
On Error Resume Next
Set MyXl = GetObject(, "Excel.Application")
If Err = 429 Then
Err = 0
Set MyXl = CreateObject("Excel.Application")
End If
' Open appropriate workbook and sheet
Set MyBook = MyXl.Workbooks.Open("c:\data\excel\New Expenses.xls")
Set MySheet = MyBook.Sheets(MyShtId)
' Select appropriate area of sheet, move to correct place in word document and copy from sheet to word.
Set MyRange = MySheet.Range("C3")
With MyRange
.Select
.Copy
End With
Selection.MoveDown Unit:=wdLine, Count:=9
Selection.Paste
Selection.Font.Size = 12
' Select appropriate area of sheet, move to appropriate area of document and copy from sheet to word.
Set MyRange = MySheet.Range("C4")
With MyRange
.Select
.Copy
End With
Selection.MoveDown Unit:=wdLine
Selection.Paste
Selection.Font.Size = 12
' Repeat the above select / copy as required.
' Finished with spreadsheet, close it.
MyBook.Close
MyXl.Quit
Hope this helps.
|
__________________
Chris Lawery
|

09-12-2003, 07:56 AM
|
 |
Junior Contributor
|
|
Join Date: Mar 2003
Location: PA, USA
Posts: 303
|
|
Quote: Originally Posted by Crittar
Code:
Sub Expenses()
'
' Expenses Macro
' Macro created 14/08/2003 by Chris Lawery
'
Dim MyShortMonth, MyShtId, MyYear, MyShortDate
' Define appropriate objects to access the sheet.
Dim MyXl As Object, MyBook As Object, MySheet As Object, MyRange As Object
Load UserForm2
UserForm2.Show
MyShortMonth = Left(MyMonth, 3)
MyYear = Year(Now)
If MyShortMonth = "Jan" Then
MyYear = MyYear - 1
End If
MyShtId = MyShortMonth & " " & MyYear
' Open excel, error code is to handle already open or not.
On Error Resume Next
Set MyXl = GetObject(, "Excel.Application")
If Err = 429 Then
Err = 0
Set MyXl = CreateObject("Excel.Application")
End If
' Open appropriate workbook and sheet
Set MyBook = MyXl.Workbooks.Open("c:\data\excel\New Expenses.xls")
Set MySheet = MyBook.Sheets(MyShtId)
' Select appropriate area of sheet, move to correct place in word document and copy from sheet to word.
Set MyRange = MySheet.Range("C3")
With MyRange
.Select
.Copy
End With
Selection.MoveDown Unit:=wdLine, Count:=9
Selection.Paste
Selection.Font.Size = 12
' Select appropriate area of sheet, move to appropriate area of document and copy from sheet to word.
Set MyRange = MySheet.Range("C4")
With MyRange
.Select
.Copy
End With
Selection.MoveDown Unit:=wdLine
Selection.Paste
Selection.Font.Size = 12
' Repeat the above select / copy as required.
' Finished with spreadsheet, close it.
MyBook.Close
MyXl.Quit
Hope this helps.
Hey:
Nice, man!
Certainly does help. I'll modify it a bit with a For/Next Loop, since every single Organization Name needs to be used to save single Cover Letter page as it's own file.
Thanks a heap. Now if I can just get it up and running by noon. These needed to go out yesterday...
--Dodd
|
__________________
"Princekimmer Skimple... Primable Skimster... I, I found something!!!!"
--Ralph Wiggum
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|