Compress Worksheet File...

  • i'm using the following code to compress a worksheet, but i get an error message that i would like to surpress...



    ???


    thank you.

  • Re: Compress Worksheet File...


    ok...i'm thinking the compression works (above)...
    and where would i use filecopy...?


    ???


    thank you.

  • Re: Compress Worksheet File...


    Hi mj,


    don't know if the compression works( didn't try it).


    I just stepped thru yoursub and got the message "Can't copy file over itself" so I thought of 'filecopy'


    [vba]
    'compressed folder name
    FolderName = "x\"
    'name file
    FileName = "ed.zip"
    'path and filename
    FileNameZip = DefPath & FileName

    'Create empty Zip File
    NewZip (FileNameZip)

    'FILECOPY
    'Copy the files to the compressed folder
    FileCopy FileNameZip, DefPath & FolderName & FileName


    [/vba]


    Cheers,


    dr

  • Re: Compress Worksheet File...


    thank you for the thought and effort...


    i just tried, no error message, but i also don't get the file compressed (it compresses, but with nothing in it...?


    (here's what i changed--one line...:)
    from

    Code
    oApp.Namespace(FileNameZip).CopyHere oApp.Namespace(FolderName).items


    to

    Code
    FileCopy FileNameZip, DefPath & FolderName & FileName


    thank you...

  • Re: Compress Worksheet File...


    Hi,


    Found this link on undocumented command line args for winzip:


    http://www.memecode.com/docs/winzip.html


    Incorporated that into a simple "Shell" command:


    [vba]
    Sub zipper()


    Dim DefPath As String
    Dim Filenam As String
    Dim FileNameZip As String
    Dim FolderNameZip As String


    On Error Resume Next


    DefPath = "c:\temp\salesmanMDB\ed\"

    Filenam = "copy"

    FolderNameZip = "c:\temp\salesmanMDB\ed\zipped\"

    FileNameZip = DefPath & Filenam & ".zip"


    Shell ("c:\program files\winzip\winzip32.exe -a " & FileNameZip & " " & DefPath & Filenam & ".xls")
    'Shell ("c:\program files\winzip\winzip32.exe -a c:\temp\salesmanMDB\ed\copy.zip c:\temp\salesmanMDB\ed\copy.xls")

    'Website with Winzip args
    'http://www.memecode.com/docs/winzip.html

    'Copy the files to the compressed folder
    FileCopy FileNameZip, FolderNameZip & Filenam & ".zip"

    End Sub[/vba]


    HTH...

  • Re: Compress Worksheet File...


    thank you...


    i'm trying not to use winzip, etc.


    but maybe, i can compress to a different folder, copy into the folder i need to, and then delete the old file...!


    i will try on monday and get back asap...


    thank you..!

  • Re: Compress Worksheet File...


    some progress...! thank you...


    i would now like to surpress the request "the folder already exists..."?


    Code
    Set oApp = CreateObject("Shell.Application")
            'Copy the files in the newly created folder
            oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(fname).items


    ???


    thank you.

  • Re: Compress Worksheet File...


    thank you...i like the idea, but the error message still pops up...


    seemingly during the following code (when it finds a previous compressed file):


    Code
    oApp.Namespace(FileNameZip).CopyHere oApp.Namespace(FolderName).items
        'Keep script waiting until Compressing is done
        On Error Resume Next
        Do Until oApp.Namespace(FileNameZip).items.Count = oApp.Namespace(FolderName).items.Count
            Application.Wait (Now + TimeValue("0:00:01"))
        Loop
  • Re: Compress Worksheet File...


    Hi mj,


    I notice you've gone back to Namespace.copyhere rather than Filecopy.


    Looks like you're copying the whole folder rather than just a single, newly created, file?



    I can't really tell without seeing your whole sub...

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!