Propósito

✔ Programação GLOBAL® - Quaisquer soluções e/ou desenvolvimento de aplicações pessoais, ou da empresa, que não constem neste Blog devem ser tratados como consultoria freelance. Queiram contatar-nos: brazilsalesforceeffectiveness@gmail.com | ESTE BLOG NÃO SE RESPONSABILIZA POR QUAISQUER DANOS PROVENIENTES DO USO DOS CÓDIGOS AQUI POSTADOS EM APLICAÇÕES PESSOAIS OU DE TERCEIROS.

.: Vitrine

Carregando artigos...

Views

Mostrando postagens com marcador path. Mostrar todas as postagens
Mostrando postagens com marcador path. Mostrar todas as postagens

PIECE OF CAKE - Extract Path From String



Function ExtractPathFromString(nString As String) As String

    ' © 2007-20 Alefe & Bete Processamento de Dados LTDA - ME, except where noted, all rights reserved.
    '      Author: André Bernardes
    '     Contact: andreluizbernardess@gmail.com | https://goo.gl/EUMbSe/
    ' Application: AutoGenClosing®
    ' Description: Extrai somente o path de uma string.

    Let ExtractPathFromString = Left(nString, InStrRev(nString, "\"))

End Function


#A&A #PIECEOFCAKE #POC #VBA

Consulte-nos

⬛◼◾▪ Social Media ▪◾◼⬛
• FACEBOOK • TWITTER • INSTAGRAM • TUMBLR • GOOGLE+ • LINKEDIN • PINTEREST

⬛◼◾▪ Blogs ▪◾◼⬛ 


⬛◼◾▪ CONTATO ▪◾◼⬛

VBA Access - Altera o Path das tabelas Conectadas - Change Link Path

Com esta função podemos alterar o path das nossas tabelas conectadas a aplicação, por um novo link.

Public Function ChangeLinkPath(strNewPath As String) As String

Dim dbs As DAO.Database
Dim strTblName As String
Dim colTbl As Collection
Dim intTbl As Integer

If strNewPath <> "" And Dir(strNewPath) <> "" Then

      Set colTbl = New Collection
      Set dbs = CurrentDb

      For intTbl = dbs.TableDefs.Count - 1 To 0 Step -1
            If dbs.TableDefs(intTbl).Connect <> "" And _
                  Not dbs.TableDefs(intTbl).Connect Like "*" & strNewPath Then
                  colTbl.Add dbs.TableDefs(intTbl).Name
                  dbs.TableDefs.Delete dbs.TableDefs(intTbl).Name
            End If
      Next intTbl

      For intTbl = colTbl.Count To 1 Step -1
            Let strTblName = colTbl(intTbl)
            DoCmd.TransferDatabase acLink, "Microsoft Access",            _ strNewPath, acTable, strTblName, strTblName
            Debug.Print "connection made to '" & strTblName & "'"
      Next intTbl

      Set dbs = Nothing
      Set colTbl = Nothing 

      Debug.Print "Feito!"
      ChangeLinkPath = "Feito!"
Else
      'Debug.Print "New path not provided. No changes made!"
      Let ChangeLinkPath = "New path not provided. No changes made!"
End If

Exit Function
End Function


Deixe os seus comentários! Envie este artigo, divulgue este link na sua rede social...

Tags: Access, change, link, path, conectar, tabela, table, 


Inline image 1

VBA Excel - Retorne o nome da Planilha



Estas duas funções UDFs (User Definition Function) retornam o nome do workbook (arquivo, a planilha utilizada).

Estas funções podem ser aproveitadas tanto diretamente nas células como internamente na codificação VBA.

Function SingleFileName() As String 
' Author: Date: Contact: 
' André Bernardes 24/11/2008 16:37 bernardess@gmail.com 
' Retorna apenas o nome do arquivo (Planilha). 

Let SingleFileName = ThisWorkbook.Name 
End Function 

Function FullFileName() As String 
' Author: Date: Contact: 
' André Bernardes 26/11/2008 09:35 bernardess@gmail.com 
' Retorna o Path, bem como o nome do arquivo (Planilha). 

    Let FullFileName = ThisWorkbook.FullName 
End Function 


Deixe os seus comentários! Envie este artigo, divulgue este link na sua rede social...


Tags: VBA, File, Name, FullName, Path, Workbook, Sheet, Active , nome, planilha, workbook,


VBA Basic - Verifica se o arquivo ou o caminho existem

| 

Esta função VBA (UDF - User Defined Function) testa se um arquivo (file) ou um caminho (path) existem ou se são válidos. 

Se desejar utilizar esta função para testar um caminho, precisará obrigatoriamente colocar "\" como último caracter do Path.


Function Check()
    Dim nFrase As String
    

    Let nFrase = "c:\Bernardes\Dashboard.xlsb"

    If DeepCheck (nFrase) Then

        MsgBox "O caminho e/ou arquivo '" & nFrase & "' existe é válido." _
          , vbInformation _
          , "Informação"

    Else

        MsgBox "O caminho e/ou arquivo '" & nFrase & "' é inválido ou não existe." _
          , vbCritical _
          , "Erro"

    End If
End Sub

Function DeepCheck (nPath As String) As Boolean    
    If Dir (nPath) = vbNullString Then
        Let DeepCheck = False
    Else
        Let DeepCheck = True
    End If    
End Function


Abaixo observamos um código simples que lista todos os arquivos de um determinado diretório.


Está configurado para usar a função Dir para obter as informações sobre onde arquivos estão armazenados na pasta / diretório. Em seguida, simplesmente grava os dados da planilha. É possível utilizar os dados em uma matriz se desejar modificar e usá-lo em outro aplicativo da suíte MS Office. Esta é uma função boa quando precisa gravar um arquivo ou realizar uma operação em todos os arquivos armazenados numa determinada pasta, mas não sabe exatamente como os arquivos são chamados ou quantos são. 


Divirta-se!



Sub ListFilesInDirectory()



Range("A5:A2000").ClearContents



Dim ListFilesInDirectory (10000, 1)

Dim One_File_List   As String

Dim Number_Of_Files_In_Directory As Long



Let One_File_List = Dir$ ("C:" + "\*.*")



Do While One_File_List <> ""

    Let ListFilesInDirectory (Number_Of_Files_In_Directory, 0) = One_File_List

    Let One_File_List = Dir$

    Let Number_Of_Files_In_Directory = Number_Of_Files_In_Directory + 1

Loop



Let Number_Of_Files_In_Directory = 0



While List_Files_In_Directory(Number_Of_Files_In_Directory, 0) <> tom


    Let Range("A5").Offset(Number_Of_Files_In_Directory, 0).Value = ListFilesInDirectory (Number_Of_Files_In_Directory, 0)


    Let Number_Of_Files_In_Directory = Number_Of_Files_In_Directory + 1

Wend



End Sub

Tags: VBA, UDF, user, defined, function, path, file, exist, Dir, directory, files


diHITT - Notícias