#1
|
|||
|
|||
Get the latest filename from directory with a macro
Hi,
Is there a possibility to make a macro to insert the filename of the latest picture from a camera roll directory? So when i take a picture i can input the filename of that picture in a word document. Kind Regards |
#2
|
||||
|
||||
If you can access the directory from Windows File Explorer then yes. Call the following function from your macro to write the name of the file in your document. Test it with the test macro and the folder in question.
Code:
Option Explicit Sub Test() MsgBox LatestFile("C:\Path") 'The path you want to test End Sub Function LatestFile(strPath As String) As String Dim oFS As Object Dim strFile As String Dim strFilename As String Dim dDate As Date Do Until Right(strPath, 1) = Chr(92) strPath = strPath & Chr(92) Loop Set oFS = CreateObject("Scripting.FileSystemObject") dDate = "01/01/1900" strFile = Dir$(strPath & "*.*") While strFile <> "" If oFS.GetFile(strPath & strFile).DateLastModified > dDate Then strFilename = strPath & strFile dDate = oFS.GetFile(strPath & strFile).DateLastModified End If strFile = Dir$() Wend LatestFile = strFilename lbl_Exit: Set oFS = Nothing Exit Function err_Handler: LatestFile = "" Err.Clear GoTo lbl_Exit End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Works, tnx!!
|
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Mailmerge Directory - TableJoiner Macro | Gwinnett | Mail Merge | 3 | 03-01-2017 09:25 AM |
Problem getting filename and directory of current word doc. | gazeranco | Word VBA | 8 | 10-29-2016 12:13 AM |
Macro Winword mailmerge split printpage with mergefield as filename | pca | Word VBA | 2 | 02-28-2014 02:43 PM |
Word Macro saving with different filename | terraterm | Word VBA | 5 | 02-28-2014 12:02 PM |
Macro for automatically adding filename without .doc | RPM7 | Word VBA | 0 | 04-29-2010 01:43 AM |