Excel - Validar nombre de un archivo antes de guardar

 
Vista:

Validar nombre de un archivo antes de guardar

Publicado por Carlos (1 intervención) el 10/04/2019 20:40:31
Buenas tardes, tengo una macro en Outlook para guardar archivos, el tema es que quiero que me guarde solo los que tienen el siguiente formato:

"cualquier texto - Exxx-035986.pdf"

La macro me funciona, tengo una variable que toma toma el nombre del archivo y lo guarda, pero me esta guardando un montón de archivos inútiles.

Como puedo validarlo con un if, o un case?

dejo el código que estoy usando

Gracias

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Public Sub SaveAttachments()
 
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem
'Object Dim objAttachments As Outlook.attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String
' Get the path to your My Documents folder
'strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
strFolderpath = "T:\17 Technical\1712 Purchasing-CLS\17.12.14 Reporte pendientes\05 Version\07 OC\"
On Error Resume Next
' Instantiate an Outlook Application object.
Set objOL = CreateObject("Outlook.Application")
' Get the collection of selected objects.
Set objSelection = objOL.ActiveExplorer.Selection
' The attachment folder needs to exist
' You can change this to another folder name of your choice
' Set the Attachment folder.
'strFolderpath = strFolderpath & "\OLAttachments\"
' Check each selected item for attachments.
For Each objMsg In objSelection
Set objAttachments = objMsg.Attachments
lngCount = objAttachments.Count
If lngCount > 0 Then
' Use a count down loop for removing items
' from a collection. Otherwise, the loop counter gets
' confused and only every other item is removed.
For i = lngCount To 1 Step -1
' Get the file name.
strFile = objAttachments.Item(i).FileName
' Combine with the path to the Temp folder.
strFile = strFolderpath & strFile
' Save the attachment as a file.
objAttachments.Item(i).SaveAsFile strFile
Next i
End If
Next
ExitSub:
Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Norberto
Val: 148
Ha mantenido su posición en Excel (en relación al último mes)
Gráfica de Excel

Validar nombre de un archivo antes de guardar

Publicado por Norberto (46 intervenciones) el 11/04/2019 09:20:16
Hola.

Para comparar el nombre del archivo con la máscara que especificas puedes usar:
1
2
3
4
5
...
    If strFile Like "*Exxx-035986.pdf" Then
        ...
    End If
....

Un saludo,

Norberto
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar