Macro to highlight File Name

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,595
Office Version
  1. 2021
Platform
  1. Windows
I have file names in Col A on sheet1 , email addresses in Col b next to the file name and a macro which enables the user to select a file and to attach to outlook and then email the file


I would like the code amended so that when the file is selected and attached the following is done


1) The file name in Col A is highlighted in Yellow once it is attached
2) If the same file is selected again , then I message will up "File already selected-do you want to attach again ?"



your assistance is most appreciated

Code:
Dim wn$
Sub SendFiles()
Dim lCount As Long, sht As Worksheet, vFilenames, sPath$, lFilecount As Long, sFullName$
 sPath = "C:\Sales Reports\"     ' your path here

ChDrive sPath
ChDir sPath
wn = ThisWorkbook.Name
vFilenames = Application.GetOpenFilename("Microsoft Excel files (*.xls),*.xlsx", , "Select the file(s) to open", , True)
If TypeName(vFilenames) = "Boolean" Then Exit Sub
For lCount = LBound(vFilenames) To UBound(vFilenames)
    Workbooks.Open vFilenames(lCount), UpdateLinks:=False
    Application.CutCopyMode = False
    Sheets(Array("summary")).Copy
    ActiveWorkbook.SaveAs Replace(vFilenames(lCount), ".xlsx", "") & "_summary.xls", FileFormat:=xlNormal
    vFilenames(lCount) = ActiveWorkbook.FullName
    For Each sht In Sheets(Array("summary"))
        Sheets(sht.Name).UsedRange.Copy
        Sheets(sht.Name).[a1].PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Next
    ActiveWorkbook.Close True
    Application.DisplayAlerts = True
    Application.CutCopyMode = True
Next
 Mailfiles "markus.fredereick@solms.com, vFilenames
 ActiveWorkbook.Close True
 'Kill vFilenames(lCount)
End Sub


Sub Mailfiles(mail_ad$, vFiles)
Dim oMailItem As Object, oOLapp As Object, lCt&, r As Range, sh As Worksheet
'Set oOLapp = CreateObject("Outlook.application")
Set oOLapp = GetObject(, "Outlook.application")            
Set oMailItem = oOLapp.CreateItem(0)
With oMailItem
    .To = mail_ad
      .Subject = Application.ActiveWorkbook.Name & "  -Sales report"
         
    .Display
    Set sh = Workbooks(wn).Sheets("sheet1")                 
'    MsgBox "This workbook: " & wn & vbLf & "Active: " & ActiveWorkbook.FullName
    Set r = sh.[a:a].Find(ActiveWorkbook.Name, sh.[a1], xlValues, xlPart)
    If Not r Is Nothing Then .cc = CStr(r.Offset(, 1).Value)
  
    
    .body = "Attached please sales Report as at  " & Format(Application.EoMonth(Date, -1), _
    "mmm yyyy") & " vs the Prior Year sales" & vbNewLine & vbNewLine
      
    
    
    .body = .body & "Regards" & vbNewLine & vbNewLine & "Dave"
    For lCt = LBound(vFiles) To UBound(vFiles)
        .Attachments.Add CStr(vFiles(lCt))
    Next
    Set oOLapp = Nothing
    Set oMailItem = Nothing
End With
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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