Is there a way to change this code to: Instead of having the email within the code to automatically read whatever is in Text7.text then use that email to send email? Here is the code. Works great except for that.
Private Sub Command5_Click()
Dim lWidth As Long, lHeight As Long
Clipboard.Clear
Call keybd_event(VK_MENU, 0, 0, 0)
Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
DoEvents
Call keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0)
Call keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0)
Printer.Print
If Width > Printer.ScaleWidth Then
lWidth = Printer.ScaleWidth
lHeight = (Printer.ScaleWidth / Width) * Height
Else
lWidth = Width
lHeight = Height
End If
Printer.PaintPicture Clipboard.GetData, 0, 0, lWidth, lHeight
Printer.EndDoc
Dim ol As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim newMail As Outlook.MailItem
'Return a reference to the MAPI layer.
Set ns = ol.GetNamespace("MAPI")
'Create a new mail message item.
Set newMail = ol.CreateItem(olMailItem)
With newMail
'Add the subject of the mail message.
.Subject = "Electricity Usage"
'Create some body text.
.Body = "Electricity Usage" & vbCrLf
.CC = "If you want a copy your email here"
'Add a recipient and test to make sure that the
'address is valid using the Resolve method.
With .Recipients.Add("Get email from Text7.text ") 'Whatever email in in Text7.text
.Type = olTo
If Not .Resolve Then
MsgBox "Unable to resolve address.", vbInformation
Exit Sub
End If
End With
'Attach a file as a link with an icon.
With .Attachments.Add _
("C:\Users\Richard\Desktop\Records for Electricity Usage\Site 1.pdf", olByValue)
.DisplayName = "Electricity Usage"
End With
'Send the mail message.
.Display
.Send
End With
'Release memory.
Set ol = Nothing
Set ns = Nothing
Set newMail = Nothing
End Sub
Private Sub Command5_Click()
Dim lWidth As Long, lHeight As Long
Clipboard.Clear
Call keybd_event(VK_MENU, 0, 0, 0)
Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
DoEvents
Call keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0)
Call keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0)
Printer.Print
If Width > Printer.ScaleWidth Then
lWidth = Printer.ScaleWidth
lHeight = (Printer.ScaleWidth / Width) * Height
Else
lWidth = Width
lHeight = Height
End If
Printer.PaintPicture Clipboard.GetData, 0, 0, lWidth, lHeight
Printer.EndDoc
Dim ol As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim newMail As Outlook.MailItem
'Return a reference to the MAPI layer.
Set ns = ol.GetNamespace("MAPI")
'Create a new mail message item.
Set newMail = ol.CreateItem(olMailItem)
With newMail
'Add the subject of the mail message.
.Subject = "Electricity Usage"
'Create some body text.
.Body = "Electricity Usage" & vbCrLf
.CC = "If you want a copy your email here"
'Add a recipient and test to make sure that the
'address is valid using the Resolve method.
With .Recipients.Add("Get email from Text7.text ") 'Whatever email in in Text7.text
.Type = olTo
If Not .Resolve Then
MsgBox "Unable to resolve address.", vbInformation
Exit Sub
End If
End With
'Attach a file as a link with an icon.
With .Attachments.Add _
("C:\Users\Richard\Desktop\Records for Electricity Usage\Site 1.pdf", olByValue)
.DisplayName = "Electricity Usage"
End With
'Send the mail message.
.Display
.Send
End With
'Release memory.
Set ol = Nothing
Set ns = Nothing
Set newMail = Nothing
End Sub