MACRO EXPERTS - NEED TO KNOW IF YOU CAN ASSIST

erica3taylor

New Member
Joined
Jan 6, 2022
Messages
6
Office Version
  1. 2019
Platform
  1. Windows
I have folders set up by manufacturer name and in those folders are there monthly invoices that are billed to them. I want a macro to be able email all invoices in each individual MFG folder to the respective MFG. Is there a way to set up a macro that can do this and possibly prompt me to input the email address to send it to or do this automatically instead of having to change each code to reflect a new email address.

So far I use this code, but I would have to change the email address each time i send to someone different and I want to avoid that and make this more automated.

Sub SendAllFilesInSeparateEmails()

Dim objShell As Object

Dim objWindowsFolder As Object

Dim objFile As Object

Dim strWindowsFolder As String

Dim objFileSystem As Object

Dim objMail As Outlook.MailItem



'Select a Windows folder

Set objShell = CreateObject("Shell.Application")

Set objWindowsFolder = objShell.BrowseForFolder(0, "Select a Windows Folder:", 0, "")



If Not objWindowsFolder Is Nothing Then

strWindowsFolder = objWindowsFolder.self.Path & "\"

Set objFileSystem = CreateObject("Scripting.FileSystemObject")

Set objWindowsFolder = objFileSystem.GetFolder(strWindowsFolder)



'Send each file in an email

For Each objFile In objWindowsFolder.Files



'Create a new mail

Set objMail = Outlook.Application.CreateItem(olMailItem)

'Change the details as per your needs

With objMail

.Subject = Left(objFile.Name, Len(objFile.Name) - (Len(objFileSystem.GetExtensionName(objFile.Name)) + 1))

.Attachments.Add objFile.Path

.Recipients.Add ("etaylor@ultradst.com")

.Recipients.ResolveAll

.Send

End With

Next



'Prompt you when completing sending

MsgBox "All done!", vbOKOnly + vbExclamation

End If

End Sub

any experts? Your assistance is greatly appreciated.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Yes that is all possible, if you just replace all with this code.
The only thing you need to do is creating a dynamic email address. You could extract that from the file

VBA Code:
Sub jec()
 Dim it As Variant
 Application.ScreenUpdating = False
 
 With Application.FileDialog(msoFileDialogFolderPicker)
    If .Show Then
      For Each it In CreateObject("scripting.filesystemobject").getfolder(.SelectedItems(1)).Files
          With CreateObject("outlook.application").createitem(0)
            .to = "your dynamic email address for the specific file"
            .cc = "test"
            .Subject = "test"
            .body = "test"
            .attachments.Add it.Path
            .display  '.send
         End With
      Next
    End If
 End With
End Sub
 
Upvote 0
Yes that is all possible, if you just replace all with this code.
The only thing you need to do is creating a dynamic email address. You could extract that from the file

VBA Code:
Sub jec()
 Dim it As Variant
 Application.ScreenUpdating = False
 
 With Application.FileDialog(msoFileDialogFolderPicker)
    If .Show Then
      For Each it In CreateObject("scripting.filesystemobject").getfolder(.SelectedItems(1)).Files
          With CreateObject("outlook.application").createitem(0)
            .to = "your dynamic email address for the specific file"
            .cc = "test"
            .Subject = "test"
            .body = "test"
            .attachments.Add it.Path
            .display  '.send
         End With
      Next
    End If
 End With
End Sub
Thank you. How do I create a dynamic email address? What is that for?
 
Upvote 0
Your goal is to send emails to the one who is addressed to the specific file right?
 
Upvote 0
Your goal is to send emails to the one who is addressed to the specific file right?
My goals is to send emails to the specific mfg that the folder is for but to be able to do it all others as well
 
Upvote 0
Yes so every file goes to an other email address, right?
If these files are Excel files, you could put their email addresses in that file, after which you can extract them (within the loop)
 
Upvote 0
Yes so every file goes to an other email address, right?
If these files are Excel files, you could put their email addresses in that file, after which you can extract them (within the loop)
yes but all files are pdf. There is a main folder then a subfolder for each MFG where each other invoices are stored
 
Upvote 0
There are more ways for doing this. You can write code in which you specify your emailaddresses. Then link them to their own “MFG” email address.

Somehow you need to link the files to an email address, I can’t look into your explorer unfortunately
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,612
Members
452,661
Latest member
Nonhle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top