Views

...

Important:

Quaisquer soluções e/ou desenvolvimento de aplicações pessoais, ou da empresa, que não constem neste Blog podem ser tratados como consultoria freelance.

E-mails

Deixe seu e-mail para receber atualizações...

eBook Promo

VBA Tips - Convertendo Drives Mapeados para UNC




O que é o fenômeno chamado BIG DATA?




Através dos caminhos UNC podemos conectar servidores e outras estações de trabalho sem mapeamento de uma unidade.

A sintaxe de um caminho UNC é o seguinte: \\servername\\sharename\\directory\\

A função a seguir, a partir de um caminho mapeado, retorna o caminho UNC. Ao evocarmos essa função, a mesma percorre a matriz resultante até a letra correspondente ser encontrada.

Uma vez encontrada, o caminho traçado é trocado pelo caminho UNC correspondente.

Function GetUNCPath(filePath As String) As String
 
Dim result() As String
Dim i As Long
Dim driveLetter As String
Dim found As Boolean
 
  ' check for valid path
  If Len(Dir(filePath)) = 0 Then
    Exit Function
  End If
 
  ' get drive letter
  Let driveLetter = Left$(filePath, 2)
 
  ' get UNC paths
  Let result = GetNetworkDrives
 
  ' look for matching drive letter in array
  For i = LBound(result) To UBound(result)
    Let found = (result(i, 1) = driveLetter)
 
      If found Then ' swap drive letter for matching UNC path
        Let GetUNCPath = Replace(filePath, driveLetter, result(i, 2))
        Exit Function
      End If
  Next i
 
End Function

Como usar:

Sub TestGetUNCPath()
 
Debug.Print GetUNCPath("T:\MyA&ACompanyDrive\Specific\Company Secrets\")
 
End Sub

Tags: VBA, UNC, Drive, mapeado, 



eBooks VBA na AMAZOM.com.br

LinkWithinBrazilVBAExcelSpecialist

Related Posts Plugin for WordPress, Blogger...

Vitrine