Zip files with same string found in file (1 Viewer)

suryu

Member
Local time
Today, 15:39
Joined
Apr 3, 2020
Messages
84
In one folder(F:\Bank\Formdetails\) multiple files are there in pdf and excel format, want to zip only if same string name found in pdf and excel

1) If excel name is "Dbk_bank.xlsx" and pdf is "Investor_Dbk_bank.pdf" then it should do zip in path (F:\Bank\Formdetails\) with name Dbk.zip
2)If excel name is "Hdfc_bank.xlsx" and pdf is "Investor_hdfc_bank.pdf" then it should do zip with name Hdfc.zip in same folder
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:09
Joined
Sep 21, 2011
Messages
7,167

suryu

Member
Local time
Today, 15:39
Joined
Apr 3, 2020
Messages
84
Start here for the zip process.

Look at FilesystemObject for file manipulation

or the DIR() function as another way to get the files.

HTH
Given code is for same files , i want for different files name in same folder
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 10:09
Joined
Sep 21, 2011
Messages
7,167
THi

Given code is for same files , i want for different files name in same folder
You are in control of what the filenames can be?
All I have given you is the basics to do what you want.
If you want someone to write it for you, you will have to wait until they reply.
 

Micron

AWF VIP
Local time
Today, 05:09
Joined
Oct 20, 2018
Messages
3,471
You will have to write a fairly complicated procedure. Assuming that IF there is no ABC.xlsx then there is no ABC.pdf AND all pdf's start with Investor, then incorporate Dir function with steps like these while looping over the folder contents:
- use Right function on file name to find xlsx files. If found, use Instr function on file name to find the first underscore, then use Left function (minus 1) to get Dbk or whatever that string is.
- now use Dir to find a file like "Investor_" & str & "_bank.pdf" and if found, zip it.

I'm guessing it is the pdf file you want to zip - you didn't say. You can skip the minus one on the Left step (or even add one) and modify the concatenation accordingly; i.e. remove the underscore(s) from the concatenation.
 
Last edited:

suryu

Member
Local time
Today, 15:39
Joined
Apr 3, 2020
Messages
84
I am trying below code, but confused how it will count one by one
Hi @arnelgp, kindly look into this
1) I want to zip different different folder with same category , if file is in pdf and excel with "dbk: string in it, then it should zip both file together
2)If hdfc found then it should zip with hdfc name


Sub zipVBA_Dual

Dim zipFileName As String
Dim unzipFolderName As String
Dim objzipItems As FolderItems
Dim objzipItem As FolderItem

'mentioned path where i want to create zip folder

zipFileName = ThisWorkbook.sheets("Paths").TextBox4.Text & "Dbk" & ".zip"

unzipFolderName = ThisWorkbook.sheets("Paths").TextBox4.Text


'Create an empty zip file
Open zippedFileFullName For Output As #1
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
Close #1

'Inititialize Shell object & file to be zipped

Dim wShApp As Shell
Set wShApp = CreateObject("Shell.Application")
Set objZipItems=wShApp.Namespace(unzipFolderName).items


With wShApp

For Each objZipItem In .Namespace(unzipFolderName).Items
If Instr(1, objZipItem.Path)," Dbk ", vbTextCompare)>0 Then
.Namespace(zipFileName).CopyHere objZipItem

End If
Next

End With


'confused what to write below for count one by one

End sub
 
Last edited:

suryu

Member
Local time
Today, 15:39
Joined
Apr 3, 2020
Messages
84
You will have to write a fairly complicated procedure. Assuming that IF there is no ABC.xlsx then there is no ABC.pdf AND all pdf's start with Investor, then incorporate Dir function with steps like these while looping over the folder contents:
- use Right function on file name to find xlsx files. If found, use Instr function on file name to find the first underscore, then use Left function (minus 1) to get Dbk or whatever that string is.
- now use Dir to find a file like "Investor_" & str & "_bank.pdf" and if found, zip it.

I'm guessing it is the pdf file you want to zip - you didn't say. You can skip the minus one on the Left step (or even add one) and modify the concatenation accordingly; i.e. remove the underscore(s) from the concatenation.
Hi
Yes i have tried , but getting some error like file not found something
thank you
 

Users who are viewing this thread

Top Bottom