A
Andrzej
I have a code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim szukana As Range
Dim Cecha As String
Dim bk As Workbook
Dim sh As Worksheet
Dim sh1 As Worksheet
Application.ScreenUpdating = False
If Not Application.Intersect(Columns("A:A"), Target) _
Is Nothing Then
Cecha = Target.Value
If Cecha = "" Then Exit Sub
On Error Resume Next
Set bk = Workbooks _
("D:\!Proj_temp_WSK\OPRZYRZADOWANIEv_6\NARZEDZIA\BAZA\katalog.xls")
On Error GoTo 0
If bk Is Nothing Then
If Err <> 0 Then
Set bk = Workbooks.Open _
(Filename:="D:\!Proj_temp_WSK\OPRZYRZADOWANIEv_6\NARZEDZIA\BAZA\katalog.xls"
)
End If
Set sh1 = bk.Worksheets(bk.Worksheets.Count)
For Each sh In bk.Worksheets
Set szukana = sh.Cells.Find(What:=Cecha, _
After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:=False)
', _
' SearchFormat:=False)
If szukana Is Nothing Then
If sh.Name = sh1.Name Then
MsgBox "Szukana cecha """ & Cecha & """ nie zosta³a odnaleziona"
ActiveWorkbook.Close
Target.Value = ""
End If
Else
bk.Activate
sh.Activate
szukana.Activate
MsgBox "Szukana cecha """ & Cecha & """ zosta³a odnaleziona"
'ActiveWorkbook.Close
'ActiveCell.Value = Cecha
End If
Next sh
End If
Application.ScreenUpdating = True
end sub
I try to ptecect my code before situation that file:
("D:\!Proj_temp_WSK\OPRZYRZADOWANIEv_6\NARZEDZIA\BAZA\katalog.xls")
was earlier opened by differend user.
If this file was earlier opened, then I would like to my code don't open
again this file, just only search for "cecha"
else
i would like to my code open the file and search for "cecha"
Someone knows more practical solution ?
this my does not work
Andrzej
Private Sub Worksheet_Change(ByVal Target As Range)
Dim szukana As Range
Dim Cecha As String
Dim bk As Workbook
Dim sh As Worksheet
Dim sh1 As Worksheet
Application.ScreenUpdating = False
If Not Application.Intersect(Columns("A:A"), Target) _
Is Nothing Then
Cecha = Target.Value
If Cecha = "" Then Exit Sub
On Error Resume Next
Set bk = Workbooks _
("D:\!Proj_temp_WSK\OPRZYRZADOWANIEv_6\NARZEDZIA\BAZA\katalog.xls")
On Error GoTo 0
If bk Is Nothing Then
If Err <> 0 Then
Set bk = Workbooks.Open _
(Filename:="D:\!Proj_temp_WSK\OPRZYRZADOWANIEv_6\NARZEDZIA\BAZA\katalog.xls"
)
End If
Set sh1 = bk.Worksheets(bk.Worksheets.Count)
For Each sh In bk.Worksheets
Set szukana = sh.Cells.Find(What:=Cecha, _
After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:=False)
', _
' SearchFormat:=False)
If szukana Is Nothing Then
If sh.Name = sh1.Name Then
MsgBox "Szukana cecha """ & Cecha & """ nie zosta³a odnaleziona"
ActiveWorkbook.Close
Target.Value = ""
End If
Else
bk.Activate
sh.Activate
szukana.Activate
MsgBox "Szukana cecha """ & Cecha & """ zosta³a odnaleziona"
'ActiveWorkbook.Close
'ActiveCell.Value = Cecha
End If
Next sh
End If
Application.ScreenUpdating = True
end sub
I try to ptecect my code before situation that file:
("D:\!Proj_temp_WSK\OPRZYRZADOWANIEv_6\NARZEDZIA\BAZA\katalog.xls")
was earlier opened by differend user.
If this file was earlier opened, then I would like to my code don't open
again this file, just only search for "cecha"
else
i would like to my code open the file and search for "cecha"
Someone knows more practical solution ?
this my does not work
Andrzej