Termo de Responsabilidade
Desenvolver com o VBA prescinde o conhecimento de manipulação de arquivos. Copiar, mover, excluir, ver quantos têm disponível em determinado local, e assim por diante. Acredito que as funcionalidades reunidas abaixo serão muito úteis nesse respeito, para ampliar o seu conhecimento. Aproveite. Aahh e deixe seus comentários.
Crie um módulo e copie tudo isso para dentro dele:Option ExplicitPrivate Declare Function ShellExecute Lib "shell32.dll" Alias _"ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _String, ByVal lpszFile As String, ByVal lpszParams As String, _ByVal lpszDir As String, ByVal FsShowCmd As Long) As LongPrivate Declare Function GetDesktopWindow Lib "user32" () As LongConst SW_SHOWNORMAL = 1Const SE_ERR_FNF = 2&Const SE_ERR_PNF = 3&Const SE_ERR_ACCESSDENIED = 5&Const SE_ERR_OOM = 8&Const SE_ERR_DLLNOTFOUND = 32&Const SE_ERR_SHARE = 26&Const SE_ERR_ASSOCINCOMPLETE = 27&Const SE_ERR_DDETIMEOUT = 28&Const SE_ERR_DDEFAIL = 29&Const SE_ERR_DDEBUSY = 30&Const SE_ERR_NOASSOC = 31&Const ERROR_BAD_FORMAT = 11&Function StartDoc (DocName As String) As LongDim Scr_hDC As LongLet Scr_hDC = GetDesktopWindow()Let StartDoc = ShellExecute(Scr_hDC, "Open", DocName, _"", "C:\", SW_SHOWNORMAL)End FunctionFunction File_Copy (strCopyFrom As String, strCopyTo As String)FileCopy strCopyFrom, strCopyToEnd FunctionFunction Current_Dir() As StringLet Current_Dir = CurDirEnd FunctionFunction Change_Dir (strChangeTo As String)ChDir strChangeToEnd FunctionFunction Change_Drive (strChangeTo As String) As StringChDrive (strChangeTo)Let Change_Drive = CurDirEnd FunctionFunction File_Exists (strToCheck As String) As IntegerDim retval As StringLet retval = Dir$(strToCheck)If retval = strToCheck ThenLet File_Exists = 1ElseLet File_Exists = 0End IfEnd FunctionFunction File_Rename (strOldName As String, strNewName As String)Name strOldName As strNewNameEnd FunctionFunction File_Delete (strToDelete As String)Kill strToDeleteEnd FunctionFunction Create_Dir (strToCreate)MkDir strToCreateEnd FunctionFunction Remove_Dir (strToRemove As String)RmDir strToRemoveEnd FunctionFunction File_Move (strMoveFrom As String, strMoveTo As String)Kill strMoveToFileCopy strMoveFrom, strMoveToEnd FunctionFunction File_ReadLine (strToRead As String, LineNum As Integer) As StringDim intCtr As IntegerDim strValue As StringDim intFNum As IntegerDim intMsg As IntegerLet intFNum = FreeFileOpen strToRead For Input As #intFNumLet intCtr = LineNumInput #intFNum, strValueLet File_ReadLine = strValueClose #intFNumEnd FunctionFunction Run_Application (strPathOfFile As String)Dim r As Long, msg As StringLet r = StartDoc (strPathOfFile)If r <= 32 Then'There was an errorSelect Case rCase SE_ERR_FNFLet msg = "Arquivo não encontrado"Case SE_ERR_PNFLet msg = "Caminho não encontrado"Case SE_ERR_ACCESSDENIEDLet msg = "Accesso protegido"Case SE_ERR_OOMLet msg = "Fora da memória"Case SE_ERR_DLLNOTFOUNDLet msg = "DLL não encontrada"Case SE_ERR_SHARELet msg = "Ocorreu uma violação de compartilhamento"Case SE_ERR_ASSOCINCOMPLETELet msg = "Associação inválida ou incompleta de arquivo"Case SE_ERR_DDETIMEOUTLet msg = "DDE Time out"Case SE_ERR_DDEFAILLet msg = "DDE transaction failed"Case SE_ERR_DDEBUSYLet msg = "DDE busy"Case SE_ERR_NOASSOCLet msg = "Nenhuma associação de arquivo para essa extensão"Case ERROR_BAD_FORMATLet msg = "Invalid EXE file or error in EXE image"Case ElseLet msg = "Erro desconhecido"End SelectEnd IfEnd FunctionFunction File_Time (strFileName As String) As StringDim strDate As StringDim intcount, intDateLen As IntegerLet strDate = FileDateTime(strFileName)Let intcount = InStr(1, strDate, " ", vbTextCompare)Let intDateLen = Len(strDate)Let File_Time = Mid$(strDate, intcount + 1, intDateLen)End FunctionFunction File_Date (strFileName As String) As StringDim strDate As StringDim intcount As IntegerLet strDate = FileDateTime (strFileName)Let intcount = InStr (1, strDate, " ", vbTextCompare)Let File_Date = CDate (Mid$(strDate, 1, intcount)End Function
References:
Tags: VBA, Tips, File, files, archive, arquivo, arquivos,
Tags: VBA, Tips, File, files, archive, arquivo, arquivos,
Nenhum comentário:
Postar um comentário