-
-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
879 additions
and
794 deletions.
There are no files selected for viewing
264 changes: 132 additions & 132 deletions
264
vba/outlook-vba/Excel Chart To Outlook.bas → ...vba-outlook/Excel to Outlook - Charts.bas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,132 +1,132 @@ | ||
Attribute VB_Name = "Module1" | ||
Sub ChartToOutlook_Multi() | ||
|
||
'Declare Outlook Variables | ||
Dim oLookApp As Outlook.Application | ||
Dim oLookFdr As Outlook.Folder | ||
Dim oLookNsp As Outlook.Namespace | ||
Dim oLookItm As Outlook.MailItem | ||
|
||
'Declare Excel Variables | ||
Dim ChrObj As ChartObject | ||
|
||
On Error Resume Next | ||
|
||
'Test if Outlook is Open | ||
Set oLookApp = GetObject(, "Outlook.Application") | ||
|
||
'If the Application isn't open it will return a 429 error | ||
If Err.Number = 429 Then | ||
|
||
'If it is not open then clear the error and create a new instance of Outlook | ||
Err.Clear | ||
Set oLookApp = New Outlook.Application | ||
|
||
End If | ||
|
||
'Create a mail item in outlook. | ||
Set oLookItm = oLookApp.CreateItem(olMailItem) | ||
|
||
'With the new email we just created. | ||
With oLookItm | ||
|
||
'Define basic infromation about the email | ||
.To = "[email protected]" | ||
.CC = "[email protected]" | ||
.Subject = "Test" | ||
.Body = "Dear Mr Lee" & vbNewLine | ||
|
||
'Show the new email. | ||
.Display | ||
|
||
'Get the Word Editor | ||
Set oWdEditor = .GetInspector.WordEditor | ||
|
||
'Loop through each chart in the active sheet | ||
For Each ChrObj In ActiveSheet.ChartObjects | ||
|
||
'Copy the Chart | ||
ChrObj.Chart.ChartArea.Copy | ||
|
||
'Define the range, insert a blank line, collapse the selection. | ||
Set oWdRng = oWdEditor.Application.ActiveDocument.Content | ||
oWdRng.InsertAfter " " & vbNewLine | ||
oWdRng.Collapse Direction:=wdCollapseEnd | ||
|
||
'Paste the object. | ||
oWdRng.Paste | ||
|
||
Next | ||
|
||
End With | ||
|
||
End Sub | ||
|
||
Sub ChartToOutlook_single() | ||
|
||
'Declare Outlook Variables | ||
Dim oLookApp As Outlook.Application | ||
Dim oLookFdr As Outlook.Folder | ||
Dim oLookNsp As Outlook.Namespace | ||
Dim oLookItm As Outlook.MailItem | ||
|
||
|
||
'Declare Excel Variables | ||
Dim ChrObj As ChartObject | ||
|
||
On Error Resume Next | ||
|
||
'Test if Outlook is Open | ||
Set oLookApp = GetObject(, "Outlook.Application") | ||
|
||
'If the Application isn't open it will return a 429 error | ||
If Err.Number = 429 Then | ||
|
||
'If it is not open then clear the error and create a new instance of Outlook | ||
Err.Clear | ||
Set oLookApp = New Outlook.Application | ||
|
||
' 'Create a NameSpace | ||
' Set oLookNsp = oLookApp.GetNamespace("MAPI") | ||
' | ||
' 'Create an Outlook Session and get the default folder. | ||
' Set oLookFdr = oLookApp.Session.GetDefaultFolder(olFolderInbox) | ||
' oLookFdr.Display | ||
|
||
End If | ||
|
||
'Create a reference to the chart and copy it. | ||
Set ChrObj = ActiveSheet.ChartObjects(1) | ||
ChrObj.Chart.ChartArea.Copy | ||
|
||
'Create a mail item in outlook. | ||
Set oLookItm = oLookApp.CreateItem(olMailItem) | ||
|
||
'With the new email we just created. | ||
With oLookItm | ||
|
||
'Define basic infromation about the email | ||
.To = "[email protected]" | ||
.CC = "[email protected]" | ||
.Subject = "Test" | ||
.Body = "Dear Mr Lee" & vbNewLine | ||
|
||
'Show the new email. | ||
.Display | ||
|
||
'Get the Word Editor | ||
Set oWdEditor = .GetInspector.WordEditor | ||
|
||
'Define the range, insert a blank line, collapse the selection. | ||
Set oWdRng = oWdEditor.Application.ActiveDocument.Content | ||
oWdRng.InsertAfter " " & vbNewLine | ||
oWdRng.Collapse Direction:=wdCollapseEnd | ||
|
||
'Paste the object. | ||
oWdRng.Paste | ||
|
||
End With | ||
|
||
End Sub | ||
|
||
|
||
Attribute VB_Name = "Module1" | ||
Sub ChartToOutlook_Multi() | ||
|
||
'Declare Outlook Variables | ||
Dim oLookApp As Outlook.Application | ||
Dim oLookFdr As Outlook.Folder | ||
Dim oLookNsp As Outlook.Namespace | ||
Dim oLookItm As Outlook.MailItem | ||
|
||
'Declare Excel Variables | ||
Dim ChrObj As ChartObject | ||
|
||
On Error Resume Next | ||
|
||
'Test if Outlook is Open | ||
Set oLookApp = GetObject(, "Outlook.Application") | ||
|
||
'If the Application isn't open it will return a 429 error | ||
If Err.Number = 429 Then | ||
|
||
'If it is not open then clear the error and create a new instance of Outlook | ||
Err.Clear | ||
Set oLookApp = New Outlook.Application | ||
|
||
End If | ||
|
||
'Create a mail item in outlook. | ||
Set oLookItm = oLookApp.CreateItem(olMailItem) | ||
|
||
'With the new email we just created. | ||
With oLookItm | ||
|
||
'Define basic infromation about the email | ||
.To = "[email protected]" | ||
.CC = "[email protected]" | ||
.Subject = "Test" | ||
.Body = "Dear Mr Lee" & vbNewLine | ||
|
||
'Show the new email. | ||
.Display | ||
|
||
'Get the Word Editor | ||
Set oWdEditor = .GetInspector.WordEditor | ||
|
||
'Loop through each chart in the active sheet | ||
For Each ChrObj In ActiveSheet.ChartObjects | ||
|
||
'Copy the Chart | ||
ChrObj.Chart.ChartArea.Copy | ||
|
||
'Define the range, insert a blank line, collapse the selection. | ||
Set oWdRng = oWdEditor.Application.ActiveDocument.Content | ||
oWdRng.InsertAfter " " & vbNewLine | ||
oWdRng.Collapse Direction:=wdCollapseEnd | ||
|
||
'Paste the object. | ||
oWdRng.Paste | ||
|
||
Next | ||
|
||
End With | ||
|
||
End Sub | ||
|
||
Sub ChartToOutlook_single() | ||
|
||
'Declare Outlook Variables | ||
Dim oLookApp As Outlook.Application | ||
Dim oLookFdr As Outlook.Folder | ||
Dim oLookNsp As Outlook.Namespace | ||
Dim oLookItm As Outlook.MailItem | ||
|
||
|
||
'Declare Excel Variables | ||
Dim ChrObj As ChartObject | ||
|
||
On Error Resume Next | ||
|
||
'Test if Outlook is Open | ||
Set oLookApp = GetObject(, "Outlook.Application") | ||
|
||
'If the Application isn't open it will return a 429 error | ||
If Err.Number = 429 Then | ||
|
||
'If it is not open then clear the error and create a new instance of Outlook | ||
Err.Clear | ||
Set oLookApp = New Outlook.Application | ||
|
||
' 'Create a NameSpace | ||
' Set oLookNsp = oLookApp.GetNamespace("MAPI") | ||
' | ||
' 'Create an Outlook Session and get the default folder. | ||
' Set oLookFdr = oLookApp.Session.GetDefaultFolder(olFolderInbox) | ||
' oLookFdr.Display | ||
|
||
End If | ||
|
||
'Create a reference to the chart and copy it. | ||
Set ChrObj = ActiveSheet.ChartObjects(1) | ||
ChrObj.Chart.ChartArea.Copy | ||
|
||
'Create a mail item in outlook. | ||
Set oLookItm = oLookApp.CreateItem(olMailItem) | ||
|
||
'With the new email we just created. | ||
With oLookItm | ||
|
||
'Define basic infromation about the email | ||
.To = "[email protected]" | ||
.CC = "[email protected]" | ||
.Subject = "Test" | ||
.Body = "Dear Mr Lee" & vbNewLine | ||
|
||
'Show the new email. | ||
.Display | ||
|
||
'Get the Word Editor | ||
Set oWdEditor = .GetInspector.WordEditor | ||
|
||
'Define the range, insert a blank line, collapse the selection. | ||
Set oWdRng = oWdEditor.Application.ActiveDocument.Content | ||
oWdRng.InsertAfter " " & vbNewLine | ||
oWdRng.Collapse Direction:=wdCollapseEnd | ||
|
||
'Paste the object. | ||
oWdRng.Paste | ||
|
||
End With | ||
|
||
End Sub | ||
|
||
|
Oops, something went wrong.