Gostaria de saber se é possível ao importar um determinado arquivo, modificar o seu nome.
Exemplo:
txtCartoes ao modificar ficaria txtCartoes_old
Eu utilizo a seguinte rotina para visualizar e exportar as informações, o que está faltando é somente modificar o nome.
Private Sub cmdImportar_Click()
On Error Resume Next
Dim Caminho As String, StrCaminho As String
Dim Titulo As String, filtro As String
filtro = "Arquivos de Retorno (*.txy)" & Chr(0) & "*.txt" & Chr(0)
Titulo = "Selecione o arquivo Mastercard"
Caminho = CurrentProject.Path
Caminho = LocalizarArquivo(Caminho, Titulo, filtro)
StrCaminho = Caminho
StrArquivo = Mid(Caminho, InStrRev(Caminho, "\") + 1)
Call ImportaTxt(StrCaminho)
End Sub
E em um módulo.
Option Compare Database
Option Explicit
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Function LocalizarArquivo(strDirIni As String, strTitulo As String, strFiltro As String)
Dim OpenFile As OPENFILENAME
Dim lReturn As Long, Pos As Integer
On Error Resume Next
OpenFile.lStructSize = Len(OpenFile)
OpenFile.lpstrFilter = strFiltro
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = String(257, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
OpenFile.lpstrInitialDir = strDirIni
OpenFile.lpstrTitle = strTitulo
OpenFile.Flags = 0
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
LocalizarArquivo = ""
Else
Pos = InStr(1, OpenFile.lpstrFile, Chr(0))
LocalizarArquivo = Left(OpenFile.lpstrFile, Pos - 1)
End If
End Function