Printing Members Of An Outlook Contact Group

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Printing Members Of An Outlook Contact Group

Post by hlewton »

OK, that did work and it put everything in line. I hope when I get a lot more contacts added and it is a 2 page print out it will still work like this.

Thank you all for your help.
Regards,
hlewton

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Printing Members Of An Outlook Contact Group

Post by hlewton »

HansV wrote:
17 Sep 2021, 20:16
No, please read more carefully. You need to set a reference to Microsoft Word 16.0 Object Library.
Yes, sorry. I did catch that and made the previous post before seeing this.
Regards,
hlewton

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Printing Members Of An Outlook Contact Group

Post by hlewton »

Leif wrote:
17 Sep 2021, 12:33
hlewton wrote:
16 Sep 2021, 23:58
So there are 2 columns that print. Some contacts left column and the right column print on the same line as it should.
Would it be resolved by setting your printer to print in landscape?

Otherwise, could you use this: How to Print a Contact Group in Only One Page in Your Outlook - Data Recovery Blog?
Leif thank you for that link. With Hans' help I got it working and it printed out just as it should have in the first place. Now all I have to do is remember about Alt+F8 to run the macro.
Regards,
hlewton

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Printing Members Of An Outlook Contact Group

Post by hlewton »

Well I have to ask another question after installing this module on all my computers. They all printed the contacts aligning the right and left column correctly. On my oldest, it is still running Microsoft 365, it printed out the contacts correctly only with a line spacing between each of them. The others did not leave a blank line spacing between contacts. Is there a reason this happens?
Regards,
hlewton

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Printing Members Of An Outlook Contact Group

Post by HansV »

The article describes how you can add a custom button to the Quick Access Toolbar that runs the macro. If you do that, you only have to click that button.
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Printing Members Of An Outlook Contact Group

Post by HansV »

Check out what happens if you start Word on the oldest computer and enter a few paragraphs.
Do the same on one of the newer computers.
Is there a difference in line spacing?
Best wishes,
Hans

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Printing Members Of An Outlook Contact Group

Post by hlewton »

HansV wrote:
17 Sep 2021, 20:49
Check out what happens if you start Word on the oldest computer and enter a few paragraphs.
Do the same on one of the newer computers.
Is there a difference in line spacing?
Yep there is a difference. I checked the Paragraph spacing settings and the one that leaves a space is set to .8 after and the ones that do no leave a space are set to 0. Is there good default setting for that space that could have been discarded over the years I have used these machines?

I did see that about the quick access toolbar. I'll see if I can get it figured out.
Regards,
hlewton

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Printing Members Of An Outlook Contact Group

Post by hlewton »

As seen in the attachment I believe I have that button on the quick access toolbar. I also believe I followed all instructions and enabled all macros but it will not print out by pressing that button. What could I have done wrong.
Print.jpg
You do not have the required permissions to view the files attached to this post.
Regards,
hlewton

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Printing Members Of An Outlook Contact Group

Post by HansV »

Did you select a contact group before clicking the button?
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Printing Members Of An Outlook Contact Group

Post by HansV »

hlewton wrote:
17 Sep 2021, 21:01
I checked the Paragraph spacing settings and the one that leaves a space is set to .8 after and the ones that do no leave a space are set to 0. Is there good default setting for that space that could have been discarded over the years I have used these machines?
If I remember correctly, the default setting when you install Word (Office) from scratch is 8 points space after. You may have changed this on the other computers.
Best wishes,
Hans

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Printing Members Of An Outlook Contact Group

Post by hlewton »

HansV wrote:
17 Sep 2021, 21:29
Did you select a contact group before clicking the button?
Yes I did. When I got into the Quick Access Toolbar I used the drop down arrow and chose Macros under the Choose commands from option. Then I placed the only macro that was there over on the Quick Access Toolbar. I then went to “Trust Center” > “Trust Center Settings” > “Macro Settings” to enable all macros. I then opened a contact group. It opened its own window. I had to move it aside to press that macro button you can see in the above attachment. And nothing happened.
Regards,
hlewton

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Printing Members Of An Outlook Contact Group

Post by hlewton »

OK, I now have a little more information. I tried running the macro as I did before using the Alt+F8 and it said the macro was disabled. See attachment.
Enabled.jpg
It won't even run when I set it back to how it was before I used the Trust Center.

Here is another attachment showing the error
Error Code.jpg
You do not have the required permissions to view the files attached to this post.
Regards,
hlewton

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Printing Members Of An Outlook Contact Group

Post by hlewton »

I just looked at one of my other computers. I looked at the macro settings in the trust center. I did not even touch it. I just wanted to see what it was set at because it had run the macro using the Alt + F8 when I created that module. Once I looked at the setting I canceled and closed the window. I got back to the contact group and tried to print it out again because I had set Word's paragraph spacing option to 8 points. Well it too bombed out saying the macro was disabled. I'm not touching other machines because I have no idea how to fix this. Apparently enabling all macros doesn't work.
Regards,
hlewton

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Printing Members Of An Outlook Contact Group

Post by hlewton »

HansV wrote:
17 Sep 2021, 19:50
Did you follow these steps from a previous reply of mine?

Select Tools > References...
Scroll down the list of references until you see "Microsoft Word 16.0 Object Library".
Tick the check box of this reference, then click OK.
Hans, I am about to try to follow all the instructions in this thread to get this same macro working on my Windows 11 machine. I assume the above macro Leif gave me will still function as it should if I do everything correctly. But I just wanted to ask, will the reference I click still be "Microsoft Word 16.0 Object Library" or is it something newer?
Regards,
hlewton

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Printing Members Of An Outlook Contact Group

Post by HansV »

The reference has to do with Microsoft Office / Microsoft 365, not with your version of Windows.
The code should still work.
Best wishes,
Hans

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Printing Members Of An Outlook Contact Group

Post by hlewton »

Thanks for that information.
Regards,
hlewton

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Printing Members Of An Outlook Contact Group

Post by hlewton »

From the above link I copied and pasted this code:

Code: Select all

Sub PrintAContactGroupOnOnePage()
    Dim objContactGroup As Outlook.DistListItem
    Dim i As Long
    Dim objMember As Outlook.recipient
    Dim strGroupInfo As String
    Dim objWordApp As Word.Application
    Dim objTempDocument As Word.Document
 
    'Get the source contact group
    Select Case Application.ActiveWindow.Class
           Case olExplorer
                Set objContactGroup = Application.ActiveExplorer.Selection(1)
           Case olInspector
                Set objContactGroup = Application.ActiveInspector.CurrentItem
    End Select
 
    For i = 1 To objContactGroup.MemberCount
        Set objMember = objContactGroup.GetMember(i)
        strGroupInfo = strGroupInfo & objMember.Name & ": " & objMember.Address & vbCr
    Next
 
    'Gather all essential info about the contact group
    strGroupInfo = "Contact Group Name: " & objContactGroup.DLName & vbCr _
      & "====================================================" & vbCr & vbCr & _
      "Members:" & vbCr & "-------------------------------------------------" _
      & vbCr & strGroupInfo
 
    'create a temp word document
    Set objWordApp = CreateObject("Word.Application")
    Set objTempDocument = objWordApp.Documents.Add
    objWordApp.Visible = True
    objTempDocument.Activate
 
    'Insert the Contact Group info into the temp word document
    With objTempDocument.Range(0, 0)
         .Text = strGroupInfo
         'Change the font to your liking
         With .Font
              .Name = "Cambria"
              .Color = wdColorBlack
              .Size = 12
        End With
    End With
 
    'Print the temp document
    objTempDocument.PrintOut
 
    'Close the temp document
    objTempDocument.Close False
    objWordApp.Quit
End Sub
It works on 3 of my other computers but I get this error on another one I was trying to update, please see attachment.
PrintMembers.jpg
On another machine I get this error and the macros are enabled in the Trust center. Please see attachment:
Macro.jpg
How can I fix these errors to make this macro run on all my machines? Thanks
You do not have the required permissions to view the files attached to this post.
Regards,
hlewton

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Printing Members Of An Outlook Contact Group

Post by HansV »

About the first error:
- Select Tools > References...
- If one of the references near the top starts with MISSING:, clear its check box.
- Locate the Microsoft Word n.0 Object Library (n depends on the version) and tick its check box.
- Click OK.

About the second error:
- Make the folder containing the document a Trusted Location for Outlook and Word and see if that makes a difference.
Best wishes,
Hans

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Printing Members Of An Outlook Contact Group

Post by hlewton »

Thank you Hans. I got the first problem solved by following your instructions. There was no "MISSING" and for some reason the Microsoft Word 16.0 Object Library had disappeared too. I know it was there long ago when I first tried to do this but, somehow it was not there now. Putting it back in the References made it work.

As far as the second problem is concerned, I changed the Enable all macros to Notifications for all macros and that made it work. Not sure why, but it seems fine now. With that Notifications for all macros enabled I feel safer, especially on the machine my wife uses.

Thanks again
Regards,
hlewton

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Printing Members Of An Outlook Contact Group

Post by hlewton »

I had to try to get the macro in this thread to work on my rebuilt computer.
I used Alt + F11 to open the Visual Basic Editor, I selected Insert Module,
I pasted this code that works on my other computer:

Code: Select all

Sub PrintAContactGroupOnOnePage()
    Dim objContactGroup As Outlook.DistListItem
    Dim i As Long
    Dim objMember As Outlook.Recipient
    Dim strGroupInfo As String
    Dim objWordApp As Word.Application
    Dim objTempDocument As Word.Document
 
    'Get the source contact group
    Select Case Application.ActiveWindow.Class
           Case olExplorer
                Set objContactGroup = Application.ActiveExplorer.Selection(1)
           Case olInspector
                Set objContactGroup = Application.ActiveInspector.CurrentItem
    End Select
 
    For i = 1 To objContactGroup.MemberCount
        Set objMember = objContactGroup.GetMember(i)
        strGroupInfo = strGroupInfo & objMember.Name & ": " & objMember.Address & vbCr
    Next
 
    'Gather all essential info about the contact group
    strGroupInfo = "Contact Group Name: " & objContactGroup.DLName & vbCr _
      & "====================================================" & vbCr & vbCr & _
      "Members:" & vbCr & "-------------------------------------------------" _
      & vbCr & strGroupInfo
 
    'create a temp word document
    Set objWordApp = CreateObject("Word.Application")
    Set objTempDocument = objWordApp.Documents.Add
    objWordApp.Visible = True
    objTempDocument.Activate
 
    'Insert the Contact Group info into the temp word document
    With objTempDocument.Range(0, 0)
         .Text = strGroupInfo
         'Change the font to your liking
         With .Font
              .Name = "Cambria"
              .Color = wdColorBlack
              .Size = 12
        End With
    End With
 
    'Print the temp document
    objTempDocument.PrintOut
I selected References and ticked Microsoft Word 16.0 Object Library
I clicked OK
I used Alt = Q to close the visual basic editor.


Back in Outlook I selected my Group Contact List
I pressed Alt + F8
Selected PrintAContactGroupOnOnePage and clicked Run
I got the error message you can see in the attachment. I don't know what to do from there. Please help me once again

Visual Basic.jpg
You do not have the required permissions to view the files attached to this post.
Regards,
hlewton