R
RHH
I very new to this VB coding game, so this may be fairly
obvious to everyone.
What's wrong with this?
~~~~~
Sub mcrFindandChangePassword()
' Basic macro for finding files.
Dim strFilePath As String
Dim strFileType As String
' The following are the defined variables
strFilePath = "H:\Excel"
strFileType = "*.xls"
'Find and open files associated with selected unit.
Set fs = Application.FileSearch
With fs
.LookIn = strFilePath
.FileName = strFileType
If .Execute > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
'Open Documents in folder.
Documents.Open FileName:=.FoundFiles(i)
With ActiveDocument
.ReadOnlyRecommended = False
.EmbedTrueTypeFonts = False
.SaveFormsData = False
.SaveSubsetFonts = False
.Password = "tiger3"
.WritePassword = ""
End With
Application.DefaultSaveFormat = ""
ActiveDocument.SaveAs FileName:=.FoundFiles(i),
FileFormat:= _
wdFormatDocument, LockComments:=False,
Password:="tiger3", _
AddToRecentFiles:=True, WritePassword:="",
ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False,
SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub
~~~~~~
I get a "Run-time error '5'" at .FileName = strFileType.
Any ideas?
Thanks in advance.
RHH
obvious to everyone.
What's wrong with this?
~~~~~
Sub mcrFindandChangePassword()
' Basic macro for finding files.
Dim strFilePath As String
Dim strFileType As String
' The following are the defined variables
strFilePath = "H:\Excel"
strFileType = "*.xls"
'Find and open files associated with selected unit.
Set fs = Application.FileSearch
With fs
.LookIn = strFilePath
.FileName = strFileType
If .Execute > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
'Open Documents in folder.
Documents.Open FileName:=.FoundFiles(i)
With ActiveDocument
.ReadOnlyRecommended = False
.EmbedTrueTypeFonts = False
.SaveFormsData = False
.SaveSubsetFonts = False
.Password = "tiger3"
.WritePassword = ""
End With
Application.DefaultSaveFormat = ""
ActiveDocument.SaveAs FileName:=.FoundFiles(i),
FileFormat:= _
wdFormatDocument, LockComments:=False,
Password:="tiger3", _
AddToRecentFiles:=True, WritePassword:="",
ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False,
SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub
~~~~~~
I get a "Run-time error '5'" at .FileName = strFileType.
Any ideas?
Thanks in advance.
RHH