G
Graham L
Hi,
My problem surounds the fact that I have 100 + files in the following
directory
C:\My Documents|Import
The first few filenames for example are ABEG, ABMN, ABXX
The files all have the extension .rpt as they have been imported via ftp
routine. What I'm aiming to do is open each file in the directory in turn,
perform identical formatting and editing in each file (for which I have code
that works!), and save the file as a word document in the same directory as
above (or preferably one called C:\My Documents|Reports). I have cobbled
together some coding, but am basically stuck and any input provided would be
incredibly welcome.
The coding seems to open the first file "ABEG", but somewhere in the routine
the filename is then lost and the routine ends up doing a loop, saving the
file with name "False" and resulting in a forced quit to get out of word. I'm
also not sure what the coding would be that ensures the macro ends normally
once the routine has been performed on each file in the directory once only.
I'd be grateful if someone could have a look at the code below and advise
accordingly
Thanks
Graham
Sub RunNR6()
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
PathToUse = "\\FINPC13\SHARE FIN01\NR6 Draft .rpt\"
myFile = Dir$(PathToUse & "*.rpt")
While myFile <> ""
Set myDoc = Documents.Open(PathToUse & myFile)
'then perform required editing and formatting
myFile = Left$(myFile, Len(myFile) - 3) = "doc"
ActiveDocument.SaveAs FileName:=myFile, FileFormat:=wdFormatDocument
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
Wend
myFile = Dir$()
End Sub
My problem surounds the fact that I have 100 + files in the following
directory
C:\My Documents|Import
The first few filenames for example are ABEG, ABMN, ABXX
The files all have the extension .rpt as they have been imported via ftp
routine. What I'm aiming to do is open each file in the directory in turn,
perform identical formatting and editing in each file (for which I have code
that works!), and save the file as a word document in the same directory as
above (or preferably one called C:\My Documents|Reports). I have cobbled
together some coding, but am basically stuck and any input provided would be
incredibly welcome.
The coding seems to open the first file "ABEG", but somewhere in the routine
the filename is then lost and the routine ends up doing a loop, saving the
file with name "False" and resulting in a forced quit to get out of word. I'm
also not sure what the coding would be that ensures the macro ends normally
once the routine has been performed on each file in the directory once only.
I'd be grateful if someone could have a look at the code below and advise
accordingly
Thanks
Graham
Sub RunNR6()
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
PathToUse = "\\FINPC13\SHARE FIN01\NR6 Draft .rpt\"
myFile = Dir$(PathToUse & "*.rpt")
While myFile <> ""
Set myDoc = Documents.Open(PathToUse & myFile)
'then perform required editing and formatting
myFile = Left$(myFile, Len(myFile) - 3) = "doc"
ActiveDocument.SaveAs FileName:=myFile, FileFormat:=wdFormatDocument
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
Wend
myFile = Dir$()
End Sub