Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access VBA email a spreadsheet with linked tables

Posted on 2011-03-06
3
Medium Priority
?
403 Views
Last Modified: 2012-05-11
Hi

I have an Excel spreadsheet that contains tables that are linked to my Access database.
The spreadsheet contains the code  ThisWorkbook.RefreshAll to automatically refresh
the data when it is opened. I need to automatically refresh these links from within Access
and email the spreadsheet via Outlook.
What Access VBA code would I use to do this
Thanks
0
Comment
Question by:Murray Brown
[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
3 Comments
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 2000 total points
ID: 35046918
Here is some code which I wrote on the fly. Please amend it for realistic situations :)

UNTESTED

'~~> Set a reference to Outlook Object Library
Sub RefreshWBook()
    Dim ObjOutlook As Outlook.Application
    Dim ObjOutlookMsg As Outlook.MailItem
    Dim objOutlookRecip As Outlook.Recipient
    Dim objOutlookAttach As Outlook.Attachment
    Dim oXLApp As Object
    Dim wbTest1 As Object
        
    '~~> Establish an EXCEL application object
    On Error Resume Next
    Set oXLApp = GetObject(, "Excel.Application")
    
    '~~> If not found then create new instance
    If Err.Number <> 0 Then
        Set oXLApp = CreateObject("Excel.Application")
    End If
    Err.Clear
    On Error GoTo 0
    
    '~~> Hide Excel
    oXLApp.Visible = False
    
    '~~> Open files
    Set wbTest1 = oXLApp.Workbooks.Open("C:\MyFile.xls")
    
    '~~> Refresh
    wbTest1.RefreshAll
    
    '~~> Close and save
    wbTest1.Close savechanges:=True
 
    Set ObjOutlook = New Outlook.Application
    Set ObjOutlookMsg = ObjOutlook.CreateItem(olMailItem)
 
    With ObjOutlookMsg
       Set objOutlookRecip = .Recipients.Add("'TO' ADDRESS GOES HERE")
       objOutlookRecip.Type = olTo
       .Subject = "SUBJECT GOES HERE"
       Set objectlookAttach = .Attachments.Add("C:\MyFile.xls")
    
       For Each objOutlookRecip In .Recipients
            If Not objOutlookRecip.Resolve Then
                 ObjOutlookMsg.Display
            End If
       Next
       .Display
       '~~> Uncomment the below to send the email
       '.Send
    End With
    
    '~~> CLEANUP (VERY IMPROTANT)
    Set ObjOutlookMsg = Nothing
    'ObjOutlook.Quit
    Set ObjOutlook = Nothing
    Set wbTest1 = Nothing
    Set wbTest2 = Nothing
    oXLApp.Quit
    Set oXLApp = Nothing
    
    MsgBox "DONE"
End Sub

Open in new window


Sid
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35060369
<What Access VBA code would I use to do this>
Can you post the code you have so far?
0
 

Author Closing Comment

by:Murray Brown
ID: 35073159
thanks very much. Sorry about late reply
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

719 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