boa tarde!
Senhores...
existe uma forma deste VBA (auto open)
Verificar se a planilha está aberta, se estiver informar o valor de uma celula dentro da planilha, porem sem abrir a mesma.
é que se a planilha abrir, ela tem um codigo para quando for fechada, desta forma, se ela for aberta, ao fechar vai executar outra e ai da problema.
Private Sub Workbook_Open()
' Test to see if the file is open.
If IsFileOpen("X:CerenoCONTROLE DE LIBERAÇÕES.xlsm") Then
Application.DisplayAlerts = False
Workbooks.Open filename:="X:CerenoCONTROLE DE LIBERAÇÕES.xlsm"
' Display a message stating the file in use.
ThisWorkbook.Application.Quit
Application.DisplayAlerts = True
MsgBox "Olá, o arquivo que você está tentando acessar, está em uso por " & Range("N1").Value
ActiveWorkbook.Close savechanges:=False
ActiveWindow.Close
Else
'Open the file in Microsoft Excel.
Workbooks.Open "X:CerenoCONTROLE DE LIBERAÇÕES.xlsm"
Range("M1").Select
ActiveCell.FormulaR1C1 = Environ$("username")
MsgBox "Seja Bem vindo(a) " & Range("n1").Value & " "
Windows("Controle de Liberaçoes.xlsm").Activate
Application.DisplayAlerts = False
ActiveWindow.Close
End If
'
' Add code here to handle case where file is NOT open by another
' user.
End Sub
' This function checks to see if a file is open or not. If the file is
' already open, it returns True. If the file is not open, it returns
' False. Otherwise, a run-time error occurs because there is
' some other problem accessing the file.
Function IsFileOpen(filename As String)
Dim filenum As Integer, errnum As Integer
On Error Resume Next ' Turn error checking off.
filenum = FreeFile() ' Get a free file number.
' Attempt to open the file and lock it.
Open filename For Input Lock Read As #filenum
Close filenum ' Close the file.
errnum = Err ' Save the error number that occurred.
On Error GoTo 0 ' Turn error checking back on.
' Check to see which error occurred.
Select Case errnum
' No error occurred.
' File is NOT already open by another user.
Case 0
IsFileOpen = False
' Error number for "Permission Denied."
' File is already opened by another user.
Case 70
IsFileOpen = True
' Another error occurred.
Case Else
Error errnum
End Select
End Function
Postado : 03/06/2014 12:40 pm