Solved

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

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

863 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

21 Experts available now in Live!

Get 1:1 Help Now