Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

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

Posted on 2011-09-23
7
Medium Priority
?
886 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

647 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