Solved

Word Mail Merge - Check to see if Outlook is "offline"

Posted on 2011-09-23
7
863 Views
Last Modified: 2012-05-12
I am working on this application to manage mail merge features

The beginning of the app toggles Outlook to work offline, then runs the mail merge and toggles Outlook back online.

What it doesn't do is check to see if outlook is offline at the beginning.

Can anybody help me check to see if outllok is online or offline at the startof this application?

I would use this check in a message box so the user can choose whether they wnt to swittch to offline or online.

Thanks
Sub amendOutbox()
    Dim olkApp As Object
    Dim mai As Object
    Dim acct As Long
    Dim fldr As Object
    
    Dim ctl As Office.CommandBarControl

    Set ctl = ActiveExplorer.CommandBars.FindControl(, 5613)
    If ctl.Enabled Then
        ctl.Execute
    End If
        
        With ActiveDocument.MailMerge
            .Destination = wdSendToEmail
            .SuppressBlankLines = True
            With .DataSource
                .FirstRecord = wdDefaultFirstRecord
                .LastRecord = wdDefaultLastRecord
            End With
            .Execute Pause:=False
        End With
        
        
        acct = getAccount
        If acct = 0 Then acct = 1
        Set olkApp = CreateObject("outlook.application")
        Set fldr = olkApp.Session.PickFolder
        If fldr Is Nothing Then Exit Sub
        For Each mai In fldr.Items
            If mai.Class = 43 Then
                With mai
                    .Importance = 2
                    .ReadReceiptRequested = True
                    .OriginatorDeliveryReportRequested = True
                    .Attachments.Add "e:\0\Access - (001) 042307.ADA Fee Proposal.pdf", 5
                    .SendUsingAccount = olkApp.Session.Accounts.Item(acct)
                    .SentOnBehalfOfName = olkApp.Session.Accounts.Item(acct)
' Need to establish the account required ... but once set can be hard coded.
                    '.Display
                    '.Save
                    .Send
'                    MsgBox acct & vbNewLine & olkApp.Session.Accounts.Item(acct)
                End With
            End If
        
        Next

    If ctl.Enabled Then
        ctl.Execute
    End If

End Sub

Open in new window

0
Comment
Question by:rogerdjr
7 Comments
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 36593491
What exactly do you mean by "toggles Outlook to work offline"?
0
 

Author Comment

by:rogerdjr
ID: 36594330
The following code switches the "Work Offline" Button - see screen cast.

Dim ctl As Office.CommandBarControl

    Set ctl = ActiveExplorer.CommandBars.FindControl(, 5613)
    If ctl.Enabled Then
        ctl.Execute
    End If

The idea is to switch outlook so it is offline before running word merge to send a series of outlook messages. This holds the the messages in the outbox so the user can add attachments, change the from address, etc. while they are still in the outbox.

Then once the edits are compete then this code toggles the "Eork Offline" button "On Line" and releases the messages.
   
    If ctl.Enabled Then
        ctl.Execute
    End If

What I want to add at the beginning of the process is a check to determine whether Outlook is On Line or Off Line, to prompt the user with the current status.

Thanks


rogerdjr-503237.flv
0
 
LVL 13

Expert Comment

by:5g6tdcv4
ID: 36961901
have you thought about using netsh to disable the network adapter until the merge is complete then re-enable it?
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 36961958
There is a boolean read-only property:

Application.Session.Offline
0
 

Author Closing Comment

by:rogerdjr
ID: 36987995
This code works great

Thanks for the input

Sub a_OutlookOutboxAddAttachnmentsToEmails()
    Dim olkApp As Object
    Dim mai As Object
    Dim acct As Long
    Dim fldr As Object
    Dim OfflineChk As Boolean
    Dim UserSelectOfflineYN As Boolean
       
    Dim ctl As Office.CommandBarControl
       
        With ActiveDocument.MailMerge
            .Destination = wdSendToEmail
            .SuppressBlankLines = True
            With .DataSource
                .FirstRecord = wdDefaultFirstRecord
                .LastRecord = wdDefaultLastRecord
            End With
            .Execute Pause:=False
        End With
       
       
        acct = getAccount
        If acct = 0 Then acct = 1
        Set olkApp = CreateObject("outlook.application")
       
        OfflineChk = olkApp.Session.Offline

MsgBox olkApp.Session.Offline
       
        Set ctl = ActiveExplorer.CommandBars.FindControl(, 5613)
        If OfflineChk = 0 Then
            UserSelectOfflineYN = MsgBox("Outlook is Currently Online" & vbNewLine & vbNewLine & "Do You Want to Switch to Offline", vbYesNo)
            If UserSelectOfflineYN = 6 Then ctl.Execute
        End If
       
MsgBox olkApp.Session.Offline
       
        Set fldr = olkApp.Session.PickFolder
        If fldr Is Nothing Then Exit Sub
        For Each mai In fldr.Items
            If mai.Class = 43 Then
                With mai
                    .Importance = 2
                    .ReadReceiptRequested = True
                    .OriginatorDeliveryReportRequested = True
                    .Attachments.Add "e:\0\Access - (001) 042307.ADA Fee Proposal.pdf", 5
                    .SendUsingAccount = olkApp.Session.Accounts.Item(acct)
                    .SentOnBehalfOfName = olkApp.Session.Accounts.Item(acct)
' Need to establish the account required ... but once set can be hard coded.
                    .Display
                    '.Save
                    '.Send
'                    MsgBox acct & vbNewLine & olkApp.Session.Accounts.Item(acct)
                End With
            End If
       
        Next

    If UserSelectOfflineYN = 6 Then
        ctl.Execute
    End If

End Sub
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now