Vba: copy file in zip folder from path to path

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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 …​
 
Upvote 0
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: 34
Upvote 0
Yes and my post #2 assertion is still true …​
 
Upvote 0
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: 8
Upvote 0
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 ) :​
 
Upvote 0
As he used the same than in my sample … :rolleyes:
 
Upvote 0

Forum statistics

Threads
1,214,605
Messages
6,120,476
Members
448,967
Latest member
visheshkotha

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
Back
Top