Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
After I click the excel file, I want to search a specific text file in
a specific folder. If the text file is not in that folder, I want workbook to close. I tried below, but it did not work. Private Sub Workbook_Open() ............ With Application.FileSearch .NewSearch .LookIn = Filename .SearchSubFolders = False .TextOrProperty = "tftougpq" .FileType = msoFileTypeAllFiles If .Execute 0 Then ThisWorkbook.Close End If End With ...... ...... End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
So you want to search the same folder for a text file with a particular name.
If that's true: Option Explicit Private Sub Workbook_Open() Dim TestStr As String Dim myFileName As String myFileName = "yourspecifictextfilename.txt" TestStr = "" On Error Resume Next TestStr = Dir(Me.Path & "\" & myFileName) On Error GoTo 0 If TestStr = "" Then 'not found Me.Close savechanges:=False End If End Sub Remember if macros are disabled (or events are not allowed to run), then this won't do what you want. Mahmut wrote: After I click the excel file, I want to search a specific text file in a specific folder. If the text file is not in that folder, I want workbook to close. I tried below, but it did not work. Private Sub Workbook_Open() ........... With Application.FileSearch .NewSearch .LookIn = Filename .SearchSubFolders = False .TextOrProperty = "tftougpq" .FileType = msoFileTypeAllFiles If .Execute 0 Then ThisWorkbook.Close End If End With ..... ..... End Sub -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Moved workbook-File name, minimize, maximize and close are not vis | Excel Worksheet Functions | |||
Close workbook without saving file | Excel Programming | |||
function to seach directory for file location | Excel Worksheet Functions | |||
File name seach within open filetype | Excel Programming | |||
File|Close w/Save fires Workbook_Open twice | Excel Programming |