vas और zipping में csv के लिए pasword जोड़ें

Nov 21 2020

Csv फ़ाइल और zipping (.zip) आउटपुट फ़ाइल में पासवर्ड के साथ एन्क्रिप्ट कैसे जोड़ें ?

Sub ExportRange()
    Dim Filename As String
    Dim NumRows As Long, NumCols As Integer
    Dim r As Long, c As Integer
    Dim Data
    Dim ExpRng As Range
    Set ExpRng = Application.Intersect(Selection, ActiveSheet.UsedRange)
    NumCols = ExpRng.Columns.Count
    NumRows = ExpRng.Rows.Count
    Filename = Application.DefaultFilePath & "\textfile.csv"
    Open Filename For Output As #1
        For r = 1 To NumRows
            For c = 1 To NumCols
                Data = ExpRng.Cells(r, c).Value
                If IsNumeric(Data) Then Data = Val(Data)
                If IsEmpty(ExpRng.Cells(r, c)) Then Data = ""
                If c <> NumCols Then
                    Write #1, Data;
                Else
                    Write #1, Data
                End If
            Next c
        Next r
    Close #1
    MsgBox ExpRng.Count & " cells were exported to " & Filename, vbInformation
End Sub

csv फ़ाइल और ** ziping ** (। zip) आउटपुट फ़ाइल के पासवर्ड के साथ एन्क्रिप्ट जोड़ें ?

जवाब

FaneDuru Nov 21 2020 at 20:50

मानक WinZip का उपयोग करके फ़ाइल को ज़िप करना भी संभव है। कृपया, अगला कोड आज़माएं। मैं WinZip कोड में पथ पर स्थापित किया है। इसे रजिस्ट्री से भी निकाला जा सकता है:

Private Sub testZipPassProtected()
 Dim strWinZipDir As String, strDestFileName As String, strSourceFileName As String
 Dim strCommand As String, strWinzip As String, strPassword As String

 strWinZipDir = "C:\Program Files\WinZip\WINZIP64.exe"
 strDestFileName = Application.DefaultFilePath & "\fileCSVStandard.zip"
 strSourceFileName = Application.DefaultFilePath & "\textfile.csv"
 strPassword = "1234"

 strCommand = """" & strWinZipDir & """ -min -a -s""" & strPassword & _
    """ -r """ & strDestFileName & """ " & """" & strSourceFileName & """"
 Shell strCommand

 MsgBox "The file " & vbCrLf & _
        """" & strSourceFileName & """ has been Zipped as " & vbCrLf & _
        """" & strDestFileName & """, using Password: " & strPassword & "."
End Sub