how can I open a password protected document through vb?

  • Thread starter Thread starter June Macleod
  • Start date Start date
J

June Macleod

I am using the GetObject(filename) command to open up an excel spreadsheet
from a VB program. The excel spreadsheet opens up but it is requesting the
password and the writerespassword. How can I supply them through code so
that the user never sees this?

Many Thanks


June
 
I don't speak the VB, but this worked ok for me in word:

Option Explicit
Sub testme01()
Dim oExcel
Dim oWorkBook
Dim xlWasRunning As Boolean

xlWasRunning = True
On Error Resume Next
Set oExcel = GetObject(, "Excel.Application")
If Err Then
Set oExcel = CreateObject("Excel.Application")
xlWasRunning = False
End If

oExcel.Visible = True

Set oWorkBook = oExcel.Workbooks.Open("C:\my documents\excel\book10.XLS", _
Password:="a", WriteResPassword:="b")

'do stuff
oWorkBook.Close False
Set oWorkBook = Nothing

If xlWasRunning Then
'do nothing
Else
oExcel.Quit
Set oExcel = Nothing
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top