+ Reply to Thread
Results 1 to 4 of 4

Zipping file from folder containing name

Hybrid View

mduff3 Zipping file from folder... 01-29-2014, 02:55 AM
Fotis1991 Re: Zipping file from folder... 01-29-2014, 03:00 AM
mduff3 Re: Zipping file from folder... 01-29-2014, 03:03 AM
Izandol Re: Zipping file from folder... 01-29-2014, 04:43 AM
  1. #1
    Registered User
    Join Date
    01-28-2014
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2010
    Posts
    6

    Exclamation Zipping file from folder containing name

    I have a code that zips files from a folder that have a certain word in the filename. When I run the macro it seems to find the file okay but then it comes up with an error like "The file name you specified is not valid or too long. Specify a different file name" and I don't know why. Here's a snippet of my code:

    Sub Zip()
    
    Dim strDate As String, SavePath As String, sFName As String
    Dim oApp As Object, iCtr As Long, I As Integer
    Dim vArr, FileNameZip
    Dim FName() As Variant
    
             ' Assign the calling object to a variable.
    ButtonName = Application.Caller
    RowCount = Cells(Cells.Rows.Count, "c").End(xlUp).Row       ' Value being searched is in column c
    
    For J = 2 To RowCount + 1
        Select Case ButtonName          ' Display the name of the button that was clicked.
            Case Range("B" & J)
    
                SavePath = "C:\Users\MDuff3\Desktop\" 'save zip location
                strDate = Format(Now, " dd-mmm-yy h-mm-ss")
                FileNameZip = SavePath & ButtonName & strDate & ".zip"
    
                FName = Array("Y:\Administration\Personnel\Certifications And Identification\CSTP\" & ButtonName & "*")
                    If IsArray(FName) = False Then
                            'do nothing
                    Else
                            'Create empty Zip File
                        NewZip (FileNameZip)
                        Set oApp = CreateObject("Shell.Application")
                        I = 0
                        For iCtr = LBound(FName) To UBound(FName)
                        vArr = Split97(FName(iCtr), "\") 'splits raw directory into array at each "/"
                        sFName = vArr(UBound(vArr)) 'picks final part of array which is the filename
                    If bIsBookOpen(sFName) Then
                    MsgBox "You can't zip a file that is open!" & vbLf & _
                           "Please close it and try again: " & FName(iCtr)
                    Else
                    'Copy the file to the compressed folder
                    I = I + 1
                    oApp.Namespace(FileNameZip).CopyHere FName(iCtr)
                    'Keep script waiting until Compressing is done
                    On Error Resume Next
                    Do Until oApp.Namespace(FileNameZip).items.Count = I
                        Application.Wait (Now + TimeValue("0:00:01"))
                    Loop
                    On Error GoTo 0
                End If
            Next iCtr
            MsgBox "You find the zipfile here: " & FileNameZip
        End If
    
             End Select
    Next
          End Sub
    The line that is problematic is coloured in red.

  2. #2
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Zipping file from folder containing name

    Can you pls explain what this thread is different from this one?

    http://www.excelforum.com/excel-prog...tton-name.html
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  3. #3
    Registered User
    Join Date
    01-28-2014
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Zipping file from folder containing name

    I've updated the code and the question that I have is completely different.

  4. #4
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Zipping file from folder containing name

    Why do you use array for FName if it is only one string?
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Zipping file from excel
    By mohanss82 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 03-15-2016, 04:36 PM
  2. Replies: 6
    Last Post: 08-11-2006, 03:41 PM
  3. Replies: 1
    Last Post: 02-13-2006, 08:10 AM
  4. Zipping a file
    By Chris in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-21-2005, 12:05 PM
  5. macro to move from file to file, folder to folder
    By davegb in forum Excel General
    Replies: 0
    Last Post: 01-21-2005, 04:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1