C
Carlos Chalhoub
Hi listmates,
I've inherited a UserForm from 1997 that I'm trying to update for our use in
this year. A few things have changed in the underlying macros and I've had
to add a couple of checkboxes. Previsously all the checkboxes ran the same
browse directory and opened Word files. However, the 2 new checkboxes must
open HTML files in txt format. How can I make the macro capture the
extension of the file and open it accordingly? I've added the main piece of
the macro. Thanks for your help.
Carlos
Function PerformGlobalChange(inputChoice As Integer, aKeyword As String,
aTitle As String, aSubject As String, aAuthor As String, aCompany As String)
Dim resp As Integer
Dim fileNames As String
Dim selectChoice As Integer
' Initialize variables
fileNames = "*.<Please enter proper file extension>"
If Windows.Count <> 0 Then
MsgBox "Please close all windows and try again.", , "SOLCORP"
End
End If
resp = MsgBox("Do you want to make global changes to the documentation
files?", vbAbortRetryIgnore + vbYesNo, "SOLCORP")
If resp = vbNo Then End
fileNames = InputBox("Enter the names of the files you want to
process.", "SOLCORP", fileNames)
If fileNames = "" Then End
MsgBox "In the next window, change to the directory where the files are,
and then click Open.", _
vbDefaultButton1, "SOLCORP"
Call ListDirectoryAndFiles(fileNames)
********* This is where I want it to decide how to open the files*********
For i = 1 To fs.FoundFiles.Count
currentFile = fs.FoundFiles.Item(i)
If fileNames = "*.htm" Then
Documents.Open Format = wdOpenFormatText
Else: Documents.Open fileName:=currentFile
End If
'***********************************************************
' Perform global changes
choice = inputChoice
If choice \ 512 = 1 Then
choice = choice Mod 512
Call mdFixHTMLCode
End If
If choice \ 256 = 1 Then
choice = choice Mod 256
Call mdOpenLinksinNewWindow
End If
If choice \ 128 = 1 Then
choice = choice Mod 128
Call ChangeCompany(aCompany)
End If
If choice \ 64 = 1 Then
choice = choice Mod 64
Call ChangeAuthor(aAuthor)
End If
If choice \ 32 = 1 Then
choice = choice Mod 32
Call ChangeSubject(aSubject)
End If
If choice \ 16 = 1 Then
choice = choice Mod 16
Call ChangeTitle(aTitle)
End If
If choice \ 8 = 1 Then
choice = choice Mod 8
Call AcceptRevision
End If
If choice \ 4 = 1 Then
choice = choice Mod 4
Call ChangeKeywords(aKeyword)
End If
If choice \ 2 = 1 Then
choice = choice Mod 2
Call RemoveTags("pcr^#^#")
End If
If choice Mod 2 = 1 Then
Call RemoveTags("fs^#^#")
End If
ActiveDocument.Close Savechanges:=wdSaveChanges
Next i
MsgBox "Macro completed.", vbDefaultButton1, "SOLCORP"
End Function
I've inherited a UserForm from 1997 that I'm trying to update for our use in
this year. A few things have changed in the underlying macros and I've had
to add a couple of checkboxes. Previsously all the checkboxes ran the same
browse directory and opened Word files. However, the 2 new checkboxes must
open HTML files in txt format. How can I make the macro capture the
extension of the file and open it accordingly? I've added the main piece of
the macro. Thanks for your help.
Carlos
Function PerformGlobalChange(inputChoice As Integer, aKeyword As String,
aTitle As String, aSubject As String, aAuthor As String, aCompany As String)
Dim resp As Integer
Dim fileNames As String
Dim selectChoice As Integer
' Initialize variables
fileNames = "*.<Please enter proper file extension>"
If Windows.Count <> 0 Then
MsgBox "Please close all windows and try again.", , "SOLCORP"
End
End If
resp = MsgBox("Do you want to make global changes to the documentation
files?", vbAbortRetryIgnore + vbYesNo, "SOLCORP")
If resp = vbNo Then End
fileNames = InputBox("Enter the names of the files you want to
process.", "SOLCORP", fileNames)
If fileNames = "" Then End
MsgBox "In the next window, change to the directory where the files are,
and then click Open.", _
vbDefaultButton1, "SOLCORP"
Call ListDirectoryAndFiles(fileNames)
********* This is where I want it to decide how to open the files*********
For i = 1 To fs.FoundFiles.Count
currentFile = fs.FoundFiles.Item(i)
If fileNames = "*.htm" Then
Documents.Open Format = wdOpenFormatText
Else: Documents.Open fileName:=currentFile
End If
'***********************************************************
' Perform global changes
choice = inputChoice
If choice \ 512 = 1 Then
choice = choice Mod 512
Call mdFixHTMLCode
End If
If choice \ 256 = 1 Then
choice = choice Mod 256
Call mdOpenLinksinNewWindow
End If
If choice \ 128 = 1 Then
choice = choice Mod 128
Call ChangeCompany(aCompany)
End If
If choice \ 64 = 1 Then
choice = choice Mod 64
Call ChangeAuthor(aAuthor)
End If
If choice \ 32 = 1 Then
choice = choice Mod 32
Call ChangeSubject(aSubject)
End If
If choice \ 16 = 1 Then
choice = choice Mod 16
Call ChangeTitle(aTitle)
End If
If choice \ 8 = 1 Then
choice = choice Mod 8
Call AcceptRevision
End If
If choice \ 4 = 1 Then
choice = choice Mod 4
Call ChangeKeywords(aKeyword)
End If
If choice \ 2 = 1 Then
choice = choice Mod 2
Call RemoveTags("pcr^#^#")
End If
If choice Mod 2 = 1 Then
Call RemoveTags("fs^#^#")
End If
ActiveDocument.Close Savechanges:=wdSaveChanges
Next i
MsgBox "Macro completed.", vbDefaultButton1, "SOLCORP"
End Function