PleaseGiveHelp
Programmer
What code do I need to access a directory on my PC and more specifically to look at the files within the directory?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
ChDrive "C:"
Chdir "C:\MyDocuments"
PathName = "C:\MyDocuments"
FileName = Dir(PathName, vbDirectory) 'Retrieves the first entry in the folder
Do While FileName <> ""
If FileName <> "." And FileName <> ".." Then
If (GetAttr(PathName & FileName) And vbDirectory) = vbDirectory Then 'this checks to see if the object is a directory
Do Nothing
Else
Do Something
End If
End If
FileName = Dir 'this gets the next object in the folder
Loop
If Left(FileName,9) = first_nine
Application.Documents.Close True
Function MergeDocs()
Dim strcurrentfilename As Variant
Dim Wrd As Word.Application
Dim newcurrentfilename As String
Dim firstnine As String
Dim originalfilename As String
Dim lastfile As String
Dim files As String
Dim i As Integer
Dim currentpathname, currentfilename As String
Set Wrd = CreateObject("Word.Application")
'ChDrive "F:"
'ChDir "F:\HNW-IT\Team Folders\Ursula\ConsentTesting\Files\"
'currentpathname = "F:\HNW-IT\Team Folders\Ursula\ConsentTesting\Files\"
currentfilename = Dir(currentpathname, vbDirectory) 'Retrieves the first entry in the folder
lastfile = ""
Do While currentfilename <> ""
If currentfilename <> "." And currentfilename <> ".." Then
If (GetAttr(currentpathname & currentfilename) And vbDirectory) <> vbDirectory Then 'makes sure the object is a file
If Right(currentfilename, 3) = "doc" Then
'If first 9 chars of current file name ARE NOT the same as the last one
If Left(currentfilename, 9) <> lastfile Then
'save and close any open file
Application.Documents.Close True
'open the next document
Application.Documents.Open currentpathname & currentfilename
'documents has same 9 digit prefix (lastfile),
Else
'If first 9 chars of current file name ARE the same as the last one
Selection.EndKey wdStory
Selection.InsertBreak wdSectionBreakNextPage
'Application.Documents.Open currentpathname & currentfilename
Selection.InsertFile currentfilename, "", False, False, False
End If
'loop to open next document with diff 9 digit sequence
End If
End If
End If
lastfile = Left(currentfilename, 9)
currentfilename = Dir 'this gets the next object in the folder
Loop
'this closes the final document
Application.Documents.Close True
End Function
Function MergeDocs()
Dim strcurrentfilename As Variant
Dim Wrd As Word.Application
Dim newcurrentfilename As String
Dim firstnine As String
Dim originalfilename As String
Dim lastfile As String
Dim files As String
Dim i As Integer
Dim currentpathname, currentfilename, storagepath As String
Set Wrd = CreateObject("Word.Application")
ChDrive "F:"
ChDir "F:\HNW-IT\Team Folders\Ursula\ConsentTesting\Files\"
currentpathname = "F:\HNW-IT\Team Folders\Ursula\ConsentTesting\Files\"
storagepath = needfoldername
currentfilename = Dir(currentpathname, vbDirectory) 'Retrieves the first entry in the folder
lastfile = ""
Do While currentfilename <> ""
If currentfilename <> "." And currentfilename <> ".." Then
If (GetAttr(currentpathname & currentfilename) And vbDirectory) <> vbDirectory Then 'makes sure the object is a file
If Right(currentfilename, 3) = "doc" Then
'If first 9 chars of current file name ARE NOT the same as the last one
If Left(currentfilename, 9) <> lastfile Then
'save and close any open file
If lastfile = "" Or lastfile = "." Or lastfile = ".." Then
Application.Documents.Close False
Else
Application.ActiveDocument.SaveAs storagepath & lastfile
Application.ActiveDocument.Close
'open the next document
End If
Application.Documents.Open currentpathname & currentfilename
'documents has same 9 digit prefix (lastfile),
Else
'If first 9 chars of current file name ARE the same as the last one
Selection.EndKey wdStory
Selection.InsertBreak wdSectionBreakNextPage
'Application.Documents.Open currentpathname & currentfilename
Selection.InsertFile currentpathname & currentfilename
'Selection.InsertFile currentfilename, "", False, False, False
End If
'loop to open next document with diff 9 digit sequence
End If
End If
End If
lastfile = Left(currentfilename, 9)
currentfilename = Dir 'this gets the next object in the folder
Loop
Application.ActiveDocument.SaveAs storagepath & lastfile
Application.ActiveDocument.Close
End Function