Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-02-2016, 06:55 PM
naeemakhtar naeemakhtar is offline Referencing to a cell in table Windows 10 Referencing to a cell in table Office 2016
Novice
Referencing to a cell in table
 
Join Date: Apr 2016
Posts: 8
naeemakhtar is on a distinguished road
Default Referencing to a cell in table

I am using a macro that will create an email that will copy and past the contents of a table into a email. A section of the table has cells for emails addresses.



In general, what is the coding to reference to a particular cell in a table assuming a table has x rows and y columns?

Trying to update the send email macro so that the send to and cc portions of the email are automatically populated based on the contents of the table.
Reply With Quote
  #2  
Old 06-02-2016, 08:46 PM
gmayor's Avatar
gmayor gmayor is offline Referencing to a cell in table Windows 10 Referencing to a cell in table Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following macro shows the way.
Code:
Sub Send_As_HTML_EMail()
Dim bStarted As Boolean
Dim olApp As Object
Dim oItem As Object
Dim oTable As Table
Dim orng As Range
Dim objdoc As Object
Dim objSel As Selection
Dim sSubject As String
Dim sTo As String
    On Error Resume Next
    Set oTable = ActiveDocument.Tables(1)
    'set the range to the first required cell
    Set orng = oTable.Cell(1, 1).Range    'range 'row1, column 1
    orng.End = orng.End - 1    'remove cell end character
    sSubject = orng.Text
    'Move the range to the next required cell
    Set orng = oTable.Cell(2, 1).Range    'range 'row2, column 1
    orng.End = orng.End - 1    'remove cell end character
    sTo = orng.Text
    'Move the range to the whole table
    Set orng = oTable.Range
    orng.Copy    'copy the table
    'Get Outlook if it's running
    Set olApp = GetObject(, "Outlook.Application")
    If Err <> 0 Then
        'Outlook wasn't running, start it from code
        Set olApp = CreateObject("Outlook.Application")
        bStarted = True
    End If
    'Create a new mailitem
    Set oItem = olApp.CreateItem(0)
    With oItem
        .BodyFormat = 2
        .Display
        Set objdoc = .GetInspector.WordEditor
        Set objSel = objdoc.Windows(1).Selection
        objSel.Paste
        .to = sTo
        .Subject = sSubject
        .Send
    End With
    If bStarted Then
        'If we started Outlook from code, then close it
        olApp.Quit
    End If
    'Clean up
    Set oItem = Nothing
    Set olApp = Nothing
lbl_Exit:
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Tags
email table



Similar Threads
Thread Thread Starter Forum Replies Last Post
Step referencing in a numbered table TomBrady Word 1 10-27-2015 03:41 PM
Referencing to a cell in table Move table cell contents from one table to another table or cell in same table donaldadams1951 Word VBA 4 02-04-2015 03:54 PM
Referencing to a cell in table Referencing rows of a table at a bookmarked location based on the value of a column jpb103 Word VBA 11 05-22-2014 08:33 AM
Referencing a value over 255 characters within a table PLUS strange formula behaviour TishyMouse Excel 2 01-08-2013 09:39 AM
Referencing to a cell in table Referencing something that isn't numbered (eg table, figure etc) hanvyj Word 2 04-10-2012 03:30 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:46 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft