Link to home
Start Free TrialLog in
Avatar of rogerdjr
rogerdjrFlag for United States of America

asked on

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

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

Avatar of Helen Feddema
Helen Feddema
Flag of United States of America image

What exactly do you mean by "toggles Outlook to work offline"?
Avatar of rogerdjr

ASKER

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
have you thought about using netsh to disable the network adapter until the merge is complete then re-enable it?
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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