Solved

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

Posted on 2011-09-23
7
867 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

777 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