Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / August 2005

Tip: Looking for answers? Try searching our database.

A Question for all of you Macro Gurus

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Glenn - 26 Aug 2005 12:52 GMT
Here's my situation.

I have in Excel a list of rooms and numbers.  For instance:

Room 205       20
Room 206       23
Room 207       24

In word I have a two page document.  I have a printer that will allow me to
do back to back, sheet insertion from a different tray, etc.

Here's what I need to do.

I need to print copies of that two page document, based on the number in
each room.  (So, I need 20 for Room 205, etc.).

Here's what I would like to do:

Have a macro, or anyway for that matter, that will Print a colored sheet
that says "Room 205 - 20" and then 20 copies, then another colored sheet
that says "Room 206 - 23" and then 23 copies.  Etc.

I know I'd have to add a third page to my document (inserted as the first
page) that would have the "Room ....(Merge Fields)".  That part of course is
no big deal.

The trick, of course, is the different number of copies.

I have complete faith someone out there can help me!

Thanks!
Doug Robbins - 26 Aug 2005 18:30 GMT
You will have to workout how to tell the printer which tray to print from,
but for the rest of it, I would just copy the data from Excel into a Word
document, which you should save with the name datadoc.doc for the purposes
of the following macro.  Also save the two page document as doccopy.doc  (if
you use different names, change the macro accordingly)  In the following
macro, you will also need to specify the path to these documents in place of
C:\[folder].  Now, I am assuming that there is a header row in the data and
that the first room number is in the second row of the table.  Then the
following macro should do what you want (except for printing the documents
for different sources.

You will find some information on controlling the printer at

http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=101

Dim datadoc As Document, divdoc As Document, doccopy As Document, datatable
As Table
Dim i As Long, j As Long
Dim room As Range, copies As Range
'Open the document that contains the roomnumbers and number of copies
Set datadoc = Documents.Open("C:\[folder]\datadoc.doc")
'Open the document of which multiple copies are required
Set doccopy = Documents.Open("C:\[folder]\doccopy.doc")
Set datatable = datadoc.Tables(1)
For i = 2 To datatable.Rows.Count
   room = datatable.Cell(i, 1).Range
   room.End = room.End - 1
   copies = datatable.Cell(i, 2).Range
   copies.End = copies.End - 1
   Set divdoc = Documents.Add
   With divdoc
       .Range.InsertAfter room & vbTab & copies
       .PrintOut
       .Close wdDoNotSaveChanges
   End With
   doccopy.PrintOut copies:=copies
Next i

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Here's my situation.
>
[quoted text clipped - 29 lines]
>
> Thanks!
Glenn - 27 Aug 2005 12:06 GMT
Thanks, but when I run the macro I get a message to debut, and the
highlighted error is:
   room = datatable.Cell(i, 1).Range

Do I need to name the table somehow in the first word document?

> You will have to workout how to tell the printer which tray to print from,
> but for the rest of it, I would just copy the data from Excel into a Word
[quoted text clipped - 67 lines]
>>
>> Thanks!
Doug Robbins - 27 Aug 2005 12:17 GMT
What does the error message say?

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Thanks, but when I run the macro I get a message to debut, and the
> highlighted error is:
[quoted text clipped - 74 lines]
>>>
>>> Thanks!
Doug Robbins - 27 Aug 2005 12:35 GMT
It should have been:

Set room = datatable/Cell(i, 1).Range

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Thanks, but when I run the macro I get a message to debut, and the
> highlighted error is:
[quoted text clipped - 74 lines]
>>>
>>> Thanks!
Glenn - 27 Aug 2005 13:08 GMT
Okay, I made that correction...had to add "Set" to the copies =  as well.
Now I get another error - Runtime Error 13...mismatch...and it brings me to

   doccopy.PrintOut copies:=copies

when I debug.

> It should have been:
>
[quoted text clipped - 81 lines]
>>>>
>>>> Thanks!
Glenn - 27 Aug 2005 13:20 GMT
I took out the : after copies and was able to print without getting that
error, however it isn't working correctly.

No matter what the number is in the table, it is only printing one copy.  I
am getting the cover page that gives the Room # and the number of copies
that it should be making.

> Okay, I made that correction...had to add "Set" to the copies =  as well.
> Now I get another error - Runtime Error 13...mismatch...and it brings me
[quoted text clipped - 89 lines]
>>>>>
>>>>> Thanks!
Doug Robbins - 27 Aug 2005 15:19 GMT
Word might consider the word copies as a reserved term, so try the following
modified code

Dim datadoc As Document, divdoc As Document, doccopy As Document, datatable
As Table
Dim i As Long, j As Long
Dim room As Range, numcopies As Range
'Open the document that contains the roomnumbers and number of copies
Set datadoc = Documents.Open("C:\[folder]\datadoc.doc")
'Open the document of which multiple copies are required
Set doccopy = Documents.Open("C:\[folder]\doccopy.doc")
Set datatable = datadoc.Tables(1)
For i = 2 To datatable.Rows.Count
   Set room = datatable.Cell(i, 1).Range
   room.End = room.End - 1
   Set numcopies = datatable.Cell(i, 2).Range
   numcopies.End = numcopies.End - 1
   Set divdoc = Documents.Add
   With divdoc
       .Range.InsertAfter room & vbTab & numcopies
       .PrintOut
       .Close wdDoNotSaveChanges
   End With
   doccopy.PrintOut copies:=val(numcopies)
Next i

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>I took out the : after copies and was able to print without getting that
>error, however it isn't working correctly.
[quoted text clipped - 97 lines]
>>>>>>
>>>>>> Thanks!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.