martin0852
09-03-2014, 04:11 AM
Hi All,
I am working on a word document which contains 13 separate unique tables.
I am having an issue whereby I need to create two emails, one which has all the tables included and another which only tables 2,6 and 9-13 included but am unable to copy and paste in this order.
The first part is easily accomplished thanks to the following code I have been using from an online source (possibly here as I have it so long I can no longer recall):
Sub Email_Click()
ActiveDocument.Save
Dim oAp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim oInsp As Outlook.Inspector
Dim wdEditor
Dim multiRange As Range
Dim strBody As String
'~~> Get/Create an instance of Outlook
Set oAp = GetObject(, "Outlook.Application")
'~~> Create new item
Set oItem = oAp.CreateItem(olMailItem)
'~~> Copy all tables
Set multiRange = ActiveDocument.Range(Start:=ActiveDocument.Tables(1).Range.Start, End:=ActiveDocument.Tables(13).Range.End)
multiRange.Copy
Set oInsp = oItem.GetInspector
Set wdEditor = oInsp.WordEditor
'~~> Display the message
oItem.Display
With oItem
.To = ""
.CC = ""
.BCC = ""
.Subject = "subject"
.HTMLBody = rng
End With
'~~> Paste the table in the email body
wdEditor.Characters(1).PasteAndFormat (wdFormatOriginalFormatting)
'~~> Flushing the Toilet
Set oItem = Nothing
Set oAp = Nothing
Set oInsp = Nothing
Set wdEditor = Nothing
End Sub
Now I have tried to loop through the code above in a basic way by going back over the copy-paste routine but the newest copied table gets nested within the top left-most cell of the last table copied into the email body so this doesn't work. Possibly I am missing something with the "flushing the toilet" part?
So my questions to ye experts are as follows:
Is there a way to copy multiple tables that are not in a nice order, so for example tables 2, 4 and 9 through 13 and paste into email body as per above code?
or failing that is there a way to loop through the copy-paste routine so that each new copied table has a space between it and the last table?
Thanks in advance for the help
I am working on a word document which contains 13 separate unique tables.
I am having an issue whereby I need to create two emails, one which has all the tables included and another which only tables 2,6 and 9-13 included but am unable to copy and paste in this order.
The first part is easily accomplished thanks to the following code I have been using from an online source (possibly here as I have it so long I can no longer recall):
Sub Email_Click()
ActiveDocument.Save
Dim oAp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim oInsp As Outlook.Inspector
Dim wdEditor
Dim multiRange As Range
Dim strBody As String
'~~> Get/Create an instance of Outlook
Set oAp = GetObject(, "Outlook.Application")
'~~> Create new item
Set oItem = oAp.CreateItem(olMailItem)
'~~> Copy all tables
Set multiRange = ActiveDocument.Range(Start:=ActiveDocument.Tables(1).Range.Start, End:=ActiveDocument.Tables(13).Range.End)
multiRange.Copy
Set oInsp = oItem.GetInspector
Set wdEditor = oInsp.WordEditor
'~~> Display the message
oItem.Display
With oItem
.To = ""
.CC = ""
.BCC = ""
.Subject = "subject"
.HTMLBody = rng
End With
'~~> Paste the table in the email body
wdEditor.Characters(1).PasteAndFormat (wdFormatOriginalFormatting)
'~~> Flushing the Toilet
Set oItem = Nothing
Set oAp = Nothing
Set oInsp = Nothing
Set wdEditor = Nothing
End Sub
Now I have tried to loop through the code above in a basic way by going back over the copy-paste routine but the newest copied table gets nested within the top left-most cell of the last table copied into the email body so this doesn't work. Possibly I am missing something with the "flushing the toilet" part?
So my questions to ye experts are as follows:
Is there a way to copy multiple tables that are not in a nice order, so for example tables 2, 4 and 9 through 13 and paste into email body as per above code?
or failing that is there a way to loop through the copy-paste routine so that each new copied table has a space between it and the last table?
Thanks in advance for the help