Vba: copy file in zip folder from path to path

Nelson78

Active Member
Joined
Sep 11, 2017
Messages
492
Office Version
  1. 2007
Hello everybody.

I've to copy a file from a folder and save it to another folder.
The folder that contains the file can be zip or not, I cannot know this info in advance.

Anyway, no problem if the folder is not "zip", I can achieve ("if" part of the code below).

Instead, if the folder is a zip one, the copy an paste operation doesn't work ("elseif" part of the code below).

As you can see, if the folder is zip, the path changes with the add of

VBA Code:
& Cell.Offset(0, 2).Value & ".zip\" &

How can I figure it out?

VBA Code:
Dim FromPath As String 
Dim ToPath As String


If FileExists("\\10.100.000.001\folder1\" & Cell.Offset(0, 2).Value & "\" & Cell.Offset(0, -3).Value & ".pdf") Then

                                    FromPath = "\\10.100.000.001\folder1\" & Cell.Offset(0, 2).Value & "\" & Cell.Offset(0, -3).Value & ".pdf"
                                    ToPath = "Z:\Folder2\YELLOW\" &  Cell.Offset(0, -3).Value & ".pdf"  
                                    
                                       FileCopy FromPath, ToPath
                                    

ElseIf FileExists("\\10.100.000.001\folder1\" & Cell.Offset(0, 2).Value & ".zip\" & Cell.Offset(0, 2).Value & "\" & Cell.Offset(0, -3).Value & ".pdf") Then
                                
                                      FileCopy FromPath, ToPath


End if
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Marc L

Well-known Member
Joined
Apr 5, 2021
Messages
1,725
Office Version
  1. 2010
Platform
  1. Windows
Hi,​
as a folder can't be a .zip file, so you must first know if the source is within a folder or within a zip file, can't be confused …​
 

Nelson78

Active Member
Joined
Sep 11, 2017
Messages
492
Office Version
  1. 2007
I'm sorry.
I'm going to try being more precise using an image.
Unfortunately, I've to cover private data, but perhaps you can undestand what I mean.
 

Attachments

  • zipp.jpg
    zipp.jpg
    36.1 KB · Views: 12

Marc L

Well-known Member
Joined
Apr 5, 2021
Messages
1,725
Office Version
  1. 2010
Platform
  1. Windows
Yes and my post #2 assertion is still true …​
 

Nelson78

Active Member
Joined
Sep 11, 2017
Messages
492
Office Version
  1. 2007

ADVERTISEMENT

I'm a little bit embarassed in not understanding the objection.

What does the attached icon represent?

And anyway, have you got any suggestions to help me?
 

Attachments

  • zipfolder.png
    zipfolder.png
    28.4 KB · Views: 1

Marc L

Well-known Member
Joined
Apr 5, 2021
Messages
1,725
Office Version
  1. 2010
Platform
  1. Windows
The folder that contains the file can be zip or not, I cannot know this info in advance.
Elaborate your logic, strategy whatever, how a VBA procedure can know something you even do not know ? …​
As coding is knowing, can't be guessing …​
As if the source file is within a .zip file it can't be a copy but an extraction !​
A sample in this thread (see also how it works on MSDOCS website with ParseName as must see ) :​
 

Marc L

Well-known Member
Joined
Apr 5, 2021
Messages
1,725
Office Version
  1. 2010
Platform
  1. Windows
As he used the same than in my sample … :rolleyes:
 

Forum statistics

Threads
1,147,748
Messages
5,742,978
Members
423,769
Latest member
LongToast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top