Results 1 to 3 of 3

Thread: [RESOLVED] Password Protect Excel File

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    688

    Resolved [RESOLVED] Password Protect Excel File

    Hi

    I have written this but it is not working

    Dim xlApp As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlSheet As Excel.Worksheet

    Set xlApp = New Excel.Application
    Set xlBook = xlApp.Workbooks.Add()
    Set xlSheet = xlBook.ActiveSheet

    xlBook.SaveAs filename
    xlBook.Protect "abc"
    xlBook.Close

    Thanks

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [RESOLVED] Password Protect Excel File

    See Workbook.SaveAs Method (Excel) for password parameters.

    Or else SaveAs after Protect?

    In any case there isn't any VB6 question here since the issue is the same no matter what language you are using for automation, and not something a VB6 programmer would have to know. You might get better answers in the Office forum.

  3. #3
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Re: [RESOLVED] Password Protect Excel File

    you need to protect the worksheet .then it will work . try the following way .
    Code:
    Hi
    
     I have written this but it is not working
    
     Dim xlApp As Excel.Application
     Dim xlBook As Excel.Workbook
     Dim xlSheet As Excel.Worksheet
    
     Set xlApp = New Excel.Application
     Set xlBook = xlApp.Workbooks.Add()
     Set xlSheet = xlBook.ActiveSheet
    
     xlBook.SaveAs filename
     'xlBook.Protect "abc"  'wrong
      xlsheet.protect "your password"
     xlBook.Close

Posting Permissions

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



Click Here to Expand Forum to Full Width