#1
|
|||
|
|||
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. |
#2
|
||||
|
||||
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 |
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 |
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 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 something that isn't numbered (eg table, figure etc) | hanvyj | Word | 2 | 04-10-2012 03:30 AM |