Word/Excel Mailmerge via VBA macro problem 
Author Message
 Word/Excel Mailmerge via VBA macro problem

My printer-support sent me a macro to manage Word/Excel MailMerge with
some thousands of data-records. Works well with a laser-printer. As
it prints out every single letter there are problems with printing on
a copier. As the copier starts a new job for every document, we do
have
a time-problem.
With normal mailmerge function for ExcelWord it's possible to create
first a single document with multiple pages, each page containing a
document referring a line in Excel. But we have too much data records
to do it that way.
The provided code makes a document to print of each ExcelLine (data
record).

Here a part of the code as is:---
j = InputBox("Mit welchem Datensatz m?chten Sie beginnen ?", "1.ter
Datensatz")
f = InputBox("Bis zu welchem Datensatz m?chten Sie drucken ?",
"letzter Datensatz")
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord
For l = 1 To j - 1
        ActiveDocument.MailMerge.DataSource.ActiveRecord =
wdNextRecord
Next l
For i = 1 To f - j + 1
    ActiveDocument.PrintOut
    ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
Next i
-----------end code sample

Is there a possibility to create a document with, lets say, 100
records, print out the document (containing 100 records) and get the
next 100 records then. And so on????? So the copier will start a new
print-job for every 100 pages and not for every single page.??
As I'm not very familiar with VBA, I don't know how to handle this.
Every advice is highly appreciated.
TIA
Curt Balluff

--
Khner Brotechnik GmbH
          - Curt Balluff -



Tue, 18 Oct 2005 14:06:03 GMT  
 Word/Excel Mailmerge via VBA macro problem
Hi Curt,

The following code is untested, but I think it should do what you want:

Dim numrecords As Long, Counter As Long
numrecords = ActiveDocument.MailMerge.DataSource.RecordCount
Counter = 1
While numrecords - Counter > 100
    With ActiveDocument.MailMerge
        .DataSource.FirstRecord = Counter
        .DataSource.LastRecord = Counter + 99
        .Destination = wdSendToPrinter
        .SuppressBlankLines = True
        .Execute
    End With
    Counter = Counter + 100
Wend
With ActiveDocument.MailMerge
    .DataSource.FirstRecord = Counter
    .DataSource.LastRecord = numrecords
    .Destination = wdSendToPrinter
    .SuppressBlankLines = True
    .Execute
End With

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP

Quote:
> My printer-support sent me a macro to manage Word/Excel MailMerge with
> some thousands of data-records. Works well with a laser-printer. As
> it prints out every single letter there are problems with printing on
> a copier. As the copier starts a new job for every document, we do
> have
> a time-problem.
> With normal mailmerge function for ExcelWord it's possible to create
> first a single document with multiple pages, each page containing a
> document referring a line in Excel. But we have too much data records
> to do it that way.
> The provided code makes a document to print of each ExcelLine (data
> record).

> Here a part of the code as is:---
> j = InputBox("Mit welchem Datensatz m?chten Sie beginnen ?", "1.ter
> Datensatz")
> f = InputBox("Bis zu welchem Datensatz m?chten Sie drucken ?",
> "letzter Datensatz")
> ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
> ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord
> For l = 1 To j - 1
>         ActiveDocument.MailMerge.DataSource.ActiveRecord =
> wdNextRecord
> Next l
> For i = 1 To f - j + 1
>     ActiveDocument.PrintOut
>     ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
> Next i
> -----------end code sample

> Is there a possibility to create a document with, lets say, 100
> records, print out the document (containing 100 records) and get the
> next 100 records then. And so on????? So the copier will start a new
> print-job for every 100 pages and not for every single page.??
> As I'm not very familiar with VBA, I don't know how to handle this.
> Every advice is highly appreciated.
> TIA
> Curt Balluff

> --
> Khner Brotechnik GmbH
>           - Curt Balluff -



Tue, 18 Oct 2005 20:19:28 GMT  
 Word/Excel Mailmerge via VBA macro problem

--


Quote:
> Hi Curt,

[...]>Zaehler = ActiveDocument.MailMerge.DataSource.RecordCount
[..]

Hi Doug,

thank you for your quick reply. We're just trying the new macro (see
bottom). It works fine. Now we want to know how many records are contained
in the Excel file.
We tried the code above but got an error (no method or data). Any hints what
we did wrong??

Curt

----------------------------------------------------------------------------
----------------------------
Attribute VB_Name = "NewMacros"
Sub AnzSerien_Druck()
' Serien_Druck Makro macht aus normalem Seriendruck mehrere Druckjobs
' Makro ursprngliche Minolta Stieber 10/99
'ge?ndert Khner 5/03 Balluff nach
'
Dim i As Integer
Dim f As Integer
Dim k As Integer
Dim l As Integer
Dim Zaehler As Long

MsgBox ("Bitte versichern Sie sich zuerst des eingestellten Druckers und
dessen Eigenschaften !!!")
MsgBox ("Jetzt gehts gleich los, bitte nur noch die Serienbrief - Vorschau
ausschalten. DANKE")
J = InputBox("Mit welchem Datensatz m?chten Sie beginnen ?", "1.ter
Datensatz")
f = InputBox("Bis zu welchem Datensatz m?chten Sie drucken ?", "letzter
Datensatz")

Zaehler = ActiveDocument.MailMerge.DataSource.RecordCount <-- here's our
problem
MsgBox(Zaehler)

Grup = CInt(InputBox("Anzahl"))
anzahl = f - J + 1
s = Fix(anzahl / Grup)
For i = 1 To s
ersterDS = J
letzterDS = ersterDS + Grup - 1
'MsgBox (ersterDS)
'MsgBox (letzterDS)
With ActiveDocument.MailMerge
 .Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
 .FirstRecord = ersterDS
  .LastRecord = letzterDS
End With
 .Execute Pause:=True
End With
ActiveDocument.PrintOut
ActiveDocument.Close False
J = J + Grup
Next i

If anzahl Mod Grup <> 0 Then
   With ActiveDocument.MailMerge
   .Destination = wdSendToNewDocument
   .SuppressBlankLines = True
   With .DataSource
   .FirstRecord = J
   .LastRecord = f
  End With
  .Execute Pause:=True
  End With
  ActiveDocument.PrintOut
  ActiveDocument.Close False
End If
End Sub
----------------------------------------------------------------------------
------------------------------------------------

-----------------------------------------------------------------------
Curt Balluff

www.curt-balluff.de
ICQ 156 842 226
------------------------------------------------------------------------

Tertium datur!
===========



Sat, 22 Oct 2005 19:49:21 GMT  
 Word/Excel Mailmerge via VBA macro problem
Hi Curt,

Using the following code when a mailmerge maindocument that has an Excel
worksheet as the datasource

MsgBox ActiveDocument.MailMerge.DataSource.RecordCount

returns the correct number of records for me.

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP

Quote:

> --


> > Hi Curt,
> [...]>Zaehler = ActiveDocument.MailMerge.DataSource.RecordCount
> [..]

> Hi Doug,

> thank you for your quick reply. We're just trying the new macro (see
> bottom). It works fine. Now we want to know how many records are contained
> in the Excel file.
> We tried the code above but got an error (no method or data). Any hints
what
> we did wrong??

> Curt

> --------------------------------------------------------------------------
--
> ----------------------------
> Attribute VB_Name = "NewMacros"
> Sub AnzSerien_Druck()
> ' Serien_Druck Makro macht aus normalem Seriendruck mehrere Druckjobs
> ' Makro ursprngliche Minolta Stieber 10/99
> 'ge?ndert Khner 5/03 Balluff nach
> '
> Dim i As Integer
> Dim f As Integer
> Dim k As Integer
> Dim l As Integer
> Dim Zaehler As Long

> MsgBox ("Bitte versichern Sie sich zuerst des eingestellten Druckers und
> dessen Eigenschaften !!!")
> MsgBox ("Jetzt gehts gleich los, bitte nur noch die Serienbrief -
Vorschau
> ausschalten. DANKE")
> J = InputBox("Mit welchem Datensatz m?chten Sie beginnen ?", "1.ter
> Datensatz")
> f = InputBox("Bis zu welchem Datensatz m?chten Sie drucken ?", "letzter
> Datensatz")

> Zaehler = ActiveDocument.MailMerge.DataSource.RecordCount <-- here's our
> problem
> MsgBox(Zaehler)

> Grup = CInt(InputBox("Anzahl"))
> anzahl = f - J + 1
> s = Fix(anzahl / Grup)
> For i = 1 To s
> ersterDS = J
> letzterDS = ersterDS + Grup - 1
> 'MsgBox (ersterDS)
> 'MsgBox (letzterDS)
> With ActiveDocument.MailMerge
>  .Destination = wdSendToNewDocument
> .SuppressBlankLines = True
> With .DataSource
>  .FirstRecord = ersterDS
>   .LastRecord = letzterDS
> End With
>  .Execute Pause:=True
> End With
> ActiveDocument.PrintOut
> ActiveDocument.Close False
> J = J + Grup
> Next i

> If anzahl Mod Grup <> 0 Then
>    With ActiveDocument.MailMerge
>    .Destination = wdSendToNewDocument
>    .SuppressBlankLines = True
>    With .DataSource
>    .FirstRecord = J
>    .LastRecord = f
>   End With
>   .Execute Pause:=True
>   End With
>   ActiveDocument.PrintOut
>   ActiveDocument.Close False
> End If
> End Sub
> --------------------------------------------------------------------------
--
> ------------------------------------------------

> -----------------------------------------------------------------------
> Curt Balluff

> www.curt-balluff.de
> ICQ 156 842 226
> ------------------------------------------------------------------------

> Tertium datur!
> ===========



Sun, 23 Oct 2005 20:48:37 GMT  
 Word/Excel Mailmerge via VBA macro problem
Hi Doug,
thank you a lot for your help. But I think we are still doing someting
wrong, because our macro refuses to work with that RecordCount thingie.
meanwhile I also got some help from a german NG and we managed to fix the
problem. I copy the code after the signature for information.

Now the macro is working and there is a new question: How do I manage that I
can call this macro from every Worddocument without import?
Is that possible?

Again, thank you for helping

Curt

--
Curt Balluff

www.curt-balluff.de
ICQ 156 842 226
------------------------------------------------------------------------
Tertium datur!
===========

Sub AnzSerien_Druck()
' Serien_Druck Makro macht aus normalem Seriendruck mehrere Druckjobs
' Makro ursprngliche Minolta Stieber 10/99
'ge?ndert Khner 5/03 Balluff nach P. Roches
'
Dim i As Integer
Dim f As Integer
Dim k As Integer
Dim l As Integer

MsgBox ("Bitte versichern Sie sich zuerst des eingestellten Druckers und
dessen Eigenschaften !!!" & vbNewLine & _
               "Jetzt gehts gleich los, bitte nur noch die Serienbrief -
Vorschau ausschalten. DANKE")

With ActiveDocument.MailMerge
  .DataSource.ActiveRecord = wdLastRecord
  zaehler = .DataSource.ActiveRecord
End With

j = 1
f = zaehler

j = InputBox("Mit welchem Datensatz m?chten Sie beginnen ?", "erster
Datensatz: ", j)
f = InputBox("Bis zu welchem Datensatz m?chten Sie drucken ?", "letzter
Datensatz: " & zaehler, f)

While f > zaehler
        f = zaehler
        f = InputBox("Bis zu welchem Datensatz m?chten Sie drucken ?",
"letzter Datensatz: " & zaehler, f)
Wend

grup = CInt(InputBox("Wie viele Dokumente zusammenfassen", "Anzahl
eingeben", "100"))
While grup < 1
        grup = CInt(InputBox("Wie viele Dokumente zusammenfassen", "Anzahl
eingeben", "100"))
Wend
anzahl = f - j + 1
s = Fix(anzahl / grup)

For i = 1 To s
        ersterDS = j
        letzterDS = ersterDS + grup - 1
        With ActiveDocument.MailMerge
                .Destination = wdSendToNewDocument
                .SuppressBlankLines = True
                With .DataSource
                        .FirstRecord = ersterDS
                        .LastRecord = letzterDS
                End With
                ' .Execute Pause:=True
        End With
        ActiveDocument.PrintOut
        ActiveDocument.Close False
        j = j + grup
Next i

If anzahl Mod grup <> 0 Then
    With ActiveDocument.MailMerge
.        Destination = wdSendToNewDocument
        .SuppressBlankLines = True
        With .DataSource
                .FirstRecord = j
                .LastRecord = f
        End With
        .Execute Pause:=True
    End With
    ActiveDocument.PrintOut
    ActiveDocument.Close False
End If

End Sub



Sun, 23 Oct 2005 21:11:57 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. >10000 lines Excel - MailMerge with word via VBA Macro

2. Excel -> Word MailMerge (Excel Macro)

3. Excel Macro via Word VBA

4. Populating a ListBox via a VBA macro when opening an Excel Workbook

5. Pasting Range from Excel 2002 via VBA to Word causes a New Workbook to open

6. Importing text file into Excel using VBA - from a word macro

7. Running a Word VBA sub/macro from Excel

8. Back to back Excel & Word VBA macros

9. Problems running macro via a word document

10. Sending a mailmerge via e-mail using VBA

11. Problem setting duplex printing via Word macro

12. Word Mailmerge macro

 

 
Powered by phpBB® Forum Software