Notifications
Clear all

MSGBOX com valor de celula em outra planilha

5 Posts
2 Usuários
0 Reactions
1,300 Visualizações
(@tiamun)
Posts: 0
New Member
Topic starter
 

Bom dia!

Senhores, sou novo no forum, preciso de uma ajudinha.

Tenho o seguinte codigo VBA...

Private Sub Workbook_Open()

' Test to see if the file is open.
If IsFileOpen("X:CerenoCONTROLE DE LIBERAÇÕES.xlsm") Then
' Display a message stating the file in use.
MsgBox "Olá, o arquivo que vocês está tentando acessar, está em uso por "
'
' Add code here to handle case where file is open by another
' user.
'
Else
' Display a message stating the file is not in use.
'MsgBox "File not in use!"
' Open the file in Microsoft Excel.
Workbooks.Open "X:CerenoCONTROLE DE LIBERAÇÕES.xlsm"
'
' Add code here to handle case where file is NOT open by another
' user.
'
End If
ThisWorkbook.Application.Quit

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

Gostaria que a MSGBOX destacada, informace o valor salvo na celula N1 do arquivo X:CerenoCONTROLE DE LIBERAÇÕES.xlsm Plan11. Após toda a mensagem.

MsgBox "Olá, o arquivo que vocês está tentando acessar, está em uso por " & "Valor da celula N1"

Existe esta possibilidade?

obrigado a todos.

 
Postado : 02/06/2014 6:41 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Bom dia tiamun,

Seja bem vindo ao fórum.

Cara, tenta assim.
Windows("CONTROLE DE LIBERAÇÕES.xlsm").Activate
MsgBox "Olá, o arquivo que vocês está tentando acessar, está em uso por " & Worksheets(" Plan11").Range("N1").Value

Qualquer coisa da o grito.
Abraço

 
Postado : 02/06/2014 7:03 am
(@tiamun)
Posts: 0
New Member
Topic starter
 

Boa tarde!

Amigo Bernardo.

o Codigo não funcionou como eu queria.

Acho que o erro não é do codigo e sim da minha planilha.

Deixa explicar o que fiz para o amigo me dar uma ideia de como resolver.

A planilha que está sendo aberta tem um vba que inseri com o Open na celula M1 o usuario da Maquina, sendo assim fiz uma procv para o N1 onde informa o nome completo do usuario da rede.

Sendo assim quando a planilha é aberta ela substitui o N1 com a informação da maquina que estou acessando por ultimo.

A ideia era que quando a plan foi aberta ela salva em M1 a informação do usuario, sendo assim, quando utilizar este vba que informei a cima em outra plan, ela verifica se está aberta a planilha e ai informa o nome do usuario (resultado da procv) em M1.

Entendeu?

Acho que preciso alterar a planilha final, de forma que ela tenha 2 opçoes, se já aberta que não salve o usuario em M1, se não aberta abra com o codigo que está no momento.
Vc pode me ajudar?

Segue o Codigo da planilha que será aberta.

Private Sub Workbook_Open()

Dim wshNetwork As Object
Dim LogonName As Variant
Set wshNetwork = CreateObject("WScript.Network")

Range("M1").Select
ActiveCell.FormulaR1C1 = Environ$("username")

'LogonName = "Olá " & wshNetwork.UserName & " Apartir de hoje, ao preencher a placa do veiculo, os dados: Hora, Data e Nome, serão preenchidos automaticamente!"
' MsgBox LogonName

MsgBox "Seja Bem vindo(a) " & Range("n1").Value & " "

End Sub

Obrigado.

 
Postado : 02/06/2014 9:29 am
(@tiamun)
Posts: 0
New Member
Topic starter
 

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
(@tiamun)
Posts: 0
New Member
Topic starter
 

Obrigado.

consegui resolver o que eu queria.

Mto obrigado pela ajuda Bernardo.

 
Postado : 04/06/2014 9:18 am