IgorDavydov
New Member
- Joined
- Jun 15, 2022
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
Hi,
I've created this abomination of a Macro in VBA from few different codes, and it seems to work fine for me.
I've sent it to my colleague and we made sure he has the same references enabled, Macros enabled, files with the same names. When we try to run it on his PC however, it doesn't do anything and doesnt produce an error message. When I went line-by-line with F8 through it, it seemed to crash after the creation of the input box pop-up (we select the range and it doesn't do anything) Set xRg = Application.InputBox("Please select email address range", "DSV", xAddress, , , , , 8)
Any ideas how to fix this? Is it because of ActiveWindow?
I have the getboiler as function in the same module.
I've created this abomination of a Macro in VBA from few different codes, and it seems to work fine for me.
I've sent it to my colleague and we made sure he has the same references enabled, Macros enabled, files with the same names. When we try to run it on his PC however, it doesn't do anything and doesnt produce an error message. When I went line-by-line with F8 through it, it seemed to crash after the creation of the input box pop-up (we select the range and it doesn't do anything) Set xRg = Application.InputBox("Please select email address range", "DSV", xAddress, , , , , 8)
Any ideas how to fix this? Is it because of ActiveWindow?
I have the getboiler as function in the same module.
VBA Code:
Sub SendEmailToAddressInCells()
Dim xRg As Range
Dim xRgEach As Range
Dim xRgVal As String
Dim xAddress As String
Dim xOutApp As Outlook.Application
Dim xMailOut As Outlook.MailItem
Dim SigString As String
Dim strbody As String
Dim Signature As String
On Error Resume Next
xAddress = ActiveWindow.RangeSelection.Address
Set xRg = Application.InputBox("Please select email address range", "DSV", xAddress, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xOutApp = CreateObject("Outlook.Application")
Set xRg = xRg.SpecialCells(xlCellTypeConstants, xlTextValues)
strbody = "Hi,<br>" & _
"<br>" & _
"Please confirm the following orders will be shipped according to the table below" & "<br>" & _
"<br>" & _
"<br>" & _
"<br>"
On Error Resume Next
SigString = Environ("appdata") & _
"\Microsoft\Signatures\ConfirmAuto.htm"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If
For Each xRgEach In xRg
xRgVal = xRgEach.Value
If xRgVal Like "?*@?*.?*" Then
Set xMailOut = xOutApp.CreateItem(olMailItem)
With xMailOut
.To = xRgVal
.CC = "abc@xyz.com"
.Subject = "Order confirmation"
.Attachments.Add "C:\Users\igor.davydov\AppData\Roaming\Microsoft\Signatures\Confirm_files\image001.png", olByValue, 0
sImgName = "image001.png"
.HTMLBody = strbody & Signature & "<img src='cid:" & sImgName & "'" & " ><br>"
.Display
'.Send
End With
End If
Next
Set xMailOut = Nothing
Set xOutApp = Nothing
Application.ScreenUpdating = True
End Sub
Last edited by a moderator: