per verificare alcuni dati, e poi richiuderlo senza salvarlo:
Workbooks(Nome).Close SaveChanges:=False
Il tutto in una frazione di secondo. In teoria.
Il problema è che il file da aprire in sola lettura contiene anch'esso delle
macro, che partono all'avvio tramite l'evento Workbook_Open().
Dato che lo apro e lo chiudo senza salvare, queste macro sono inutili, e
vorrei poter dirgli "aprimi il file senza attivarmi le macro" nella
istruzione Workbooks.Open ecc...
E' possibile?
Grazie mille
Ciao
bizkit82
=============
E' possibile?
=============
Prova qualcosa del genere:
'===========>>
Public Sub Tester()
Dim WB As Workbook
Dim myFolder As String
Dim myDrive As String
Dim sSeparator As String
Dim sStr As String
Const sPath As String = _
"C:\Users\Norman\Documents" '<<=== da CAMBIARE
Const sFile As String = "Pippo.xls" '<<=== da CAMBIARE
sSeparator = Application.PathSeparator
If Right(sPath, 1) <> sSeparator Then
sStr = sPath & sSeparator & sFile
Else
sStr = sPath & sFile
End If
myFolder = CurDir
myDrive = CurDir
On Error GoTo XIT
With Application
.ScreenUpdating = False
.EnableEvents = False
Set WB = Workbooks.Open( _
Filename:=sStr, _
ReadOnly:=True)
' Tuo codice '<<============
XIT:
WB.Close SaveChanges:=False
.ScreenUpdating = True
.EnableEvents = True
End With
ChDrive sPath
ChDir sPath
End Sub
'<<===========
---
Regards.
Norman
Ciao
bizkit82
Infatti, il codice era inteso come:
'===========>>
Public Sub Tester()
Dim WB As Workbook
Dim myFolder As String
Dim myDrive As String
Dim sSeparator As String
Dim sStr As String
Const sPath As String = _
"C:\Users\Norman\Documents" '<<=== da CAMBIARE
Const sFile As String = "Pippo.xls" '<<=== da CAMBIARE
sSeparator = Application.PathSeparator
If Right(sPath, 1) <> sSeparator Then
sStr = sPath & sSeparator & sFile
Else
sStr = sPath & sFile
End If
myFolder = CurDir
myDrive = CurDir
ChDrive sPath
ChDir sPath
On Error GoTo XIT
With Application
.ScreenUpdating = False
.EnableEvents = False
Set WB = Workbooks.Open( _
Filename:=sStr, _
ReadOnly:=True)
' Tuo codice '<<============
XIT:
WB.Close SaveChanges:=False
.ScreenUpdating = True
.EnableEvents = True
End With
ChDrive myFolder
ChDir myFolder
Per questo ho detto che funziona alla grande.
Ciao e grazie ancora
bizkit82
=============
Ehm... ad essere sincero io non ho copiato il tuo codice... (non volermi
male).
Mi bastava sapere la parola magica: Application.EnableEvents = False
Per questo ho detto che funziona alla grande.
=============
Per quanto riguarda l'istruzione:
Application.EnableEvents = False
E' necessario assicurati che lo
settaggio sia riattivato - anche
nel caso di un errore non previsto
nel codice. Quindi, nel mio codice
di esempio, ho preceduto
l'istruzione con:
On Error GoTo XIT
e, succesivamente:
XIT:
[...]
.EnableEvents = True
[...]
End Sub.
---
Regards.
Norman
Ciao
bizkit82