VBA - Excel 2011 - Mac - Searching for file within a folder

AdamPickard

New Member
Joined
Jul 6, 2015
Messages
14
Hello guys,

I am having an issue when trying to search for a file (based on a cell reference) within a specific directory using the MacID function.

The code I am currently using will attach only the entire folder and not the specific file within the folder:

Function getFileName(sSearchTerm As String) As String

getFileName = Dir("Macintosh HD:Users:AdamPickard:Dropbox:InvoicesReceipts:Invoices:", MacID("TEXT"))


'Also tried MacID("DOCX")
'Also tried Dir("Macintosh HD:Users:AdamPickard:Dropbox:InvoicesReceipts:Invoices:") & sSearchTerm & MacID("TEXT") - This returned no files


End Function




Sub Email_Invoice()
'For Excel 2011 for the Mac and Apple Mail
Dim wb As Workbook

'TEST BELOW
Dim sSearchTerm As String
Dim sFileName As String


sSearchTerm = Range("C8").Value

sFileName = getFileName(sSearchTerm)


If Val(Application.Version) < 14 Then Exit Sub


Set wb = ActiveWorkbook
With wb
MailFromMacWithMail bodycontent:="Dear " & Range("C6").Value & "," & vbNewLine & vbNewLine & "Please find attached your Invoice." & vbNewLine & vbNewLine & "Kind Regards," & vbNewLine & vbNewLine & vbNewLine & "The Element 8 team" & vbNewLine & vbNewLine, _
mailsubject:="Element 8 - Outstanding Invoice - Invoice Number - " & Range("C8").Value, _
toaddress:=Range("C9").Value, _
ccaddress:="", _
bccaddress:="", _
attachment:="Macintosh HD:Users:AdamPickard:Dropbox:InvoicesReceipts:Invoices:" & sFileName, _
displaymail:=True
End With
Set wb = Nothing


End Sub

The cell "C8" is an invoice number which can only be located within 1 saved file name.

Any suggestions?

Thanks,
 
Last edited:

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,215,332
Messages
6,124,314
Members
449,153
Latest member
JazzSingerNL

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