Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Open a Word document from Excel and change its password

Hi everyone,
Could anybody tell me how to open a word document from within an
Excel macro and put a read only password, save and close the document,
return focus back to excel. I have the following codes in mind....

ActiveDocument.Password = "mypassword"
ActiveDocument.save
ActiveDocuemnt.close

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Open a Word document from Excel and change its password

This worked ok for me:

Option Explicit
Sub testme()

'Dim WDApp As Word.Application
'Dim WDDoc As Word.Document
Dim WDApp As Object
Dim WDDoc As Object
Dim myDocName As String
Dim myPWD As String
Dim WordWasRunning As Boolean
Dim testStr As String

myDocName = "C:\my documents\word\doc10.doc"
myPWD = "mypassword"

testStr = ""
On Error Resume Next
testStr = Dir(myDocName)
On Error GoTo 0
If testStr = "" Then
MsgBox "Word file not found!"
Exit Sub
End If

WordWasRunning = True
On Error Resume Next
Set WDApp = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set WDApp = CreateObject("Word.Application")
WordWasRunning = False
End If

WDApp.Visible = True 'at least for testing!

Set WDDoc = WDApp.documents.Open(Filename:=myDocName)

WDDoc.WritePassword = myPWD
WDDoc.Close savechanges:=True

If WordWasRunning Then
'leave it running
Else
WDApp.Quit
End If

Set WDDoc = Nothing
Set WDApp = Nothing

End Sub



RosH wrote:

Hi everyone,
Could anybody tell me how to open a word document from within an
Excel macro and put a read only password, save and close the document,
return focus back to excel. I have the following codes in mind....

ActiveDocument.Password = "mypassword"
ActiveDocument.save
ActiveDocuemnt.close


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Open a Word document from Excel and change its password

I needed some help on this same issue and found this
while browsing. Iused this and it worked GREAT. Thank-you

"Dave Peterson" wrote:

This worked ok for me:

Option Explicit
Sub testme()

'Dim WDApp As Word.Application
'Dim WDDoc As Word.Document
Dim WDApp As Object
Dim WDDoc As Object
Dim myDocName As String
Dim myPWD As String
Dim WordWasRunning As Boolean
Dim testStr As String

myDocName = "C:\my documents\word\doc10.doc"
myPWD = "mypassword"

testStr = ""
On Error Resume Next
testStr = Dir(myDocName)
On Error GoTo 0
If testStr = "" Then
MsgBox "Word file not found!"
Exit Sub
End If

WordWasRunning = True
On Error Resume Next
Set WDApp = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set WDApp = CreateObject("Word.Application")
WordWasRunning = False
End If

WDApp.Visible = True 'at least for testing!

Set WDDoc = WDApp.documents.Open(Filename:=myDocName)

WDDoc.WritePassword = myPWD
WDDoc.Close savechanges:=True

If WordWasRunning Then
'leave it running
Else
WDApp.Quit
End If

Set WDDoc = Nothing
Set WDApp = Nothing

End Sub



RosH wrote:

Hi everyone,
Could anybody tell me how to open a word document from within an
Excel macro and put a read only password, save and close the document,
return focus back to excel. I have the following codes in mind....

ActiveDocument.Password = "mypassword"
ActiveDocument.save
ActiveDocuemnt.close


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Open a Word document from Excel and change its password

Google is nice!

REVA wrote:

I needed some help on this same issue and found this
while browsing. Iused this and it worked GREAT. Thank-you

"Dave Peterson" wrote:

This worked ok for me:

Option Explicit
Sub testme()

'Dim WDApp As Word.Application
'Dim WDDoc As Word.Document
Dim WDApp As Object
Dim WDDoc As Object
Dim myDocName As String
Dim myPWD As String
Dim WordWasRunning As Boolean
Dim testStr As String

myDocName = "C:\my documents\word\doc10.doc"
myPWD = "mypassword"

testStr = ""
On Error Resume Next
testStr = Dir(myDocName)
On Error GoTo 0
If testStr = "" Then
MsgBox "Word file not found!"
Exit Sub
End If

WordWasRunning = True
On Error Resume Next
Set WDApp = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set WDApp = CreateObject("Word.Application")
WordWasRunning = False
End If

WDApp.Visible = True 'at least for testing!

Set WDDoc = WDApp.documents.Open(Filename:=myDocName)

WDDoc.WritePassword = myPWD
WDDoc.Close savechanges:=True

If WordWasRunning Then
'leave it running
Else
WDApp.Quit
End If

Set WDDoc = Nothing
Set WDApp = Nothing

End Sub



RosH wrote:

Hi everyone,
Could anybody tell me how to open a word document from within an
Excel macro and put a read only password, save and close the document,
return focus back to excel. I have the following codes in mind....

ActiveDocument.Password = "mypassword"
ActiveDocument.save
ActiveDocuemnt.close


--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I forgot my password to open an excel document, how do I open it? chris ohearn Excel Discussion (Misc queries) 1 August 11th 08 02:32 PM
change excel document into word document mrsb Excel Discussion (Misc queries) 6 August 28th 07 12:58 PM
Open A Word Document from Excel roadkill Excel Programming 4 November 4th 05 10:15 PM
How to change a excel document into a word document? wannaknow Excel Discussion (Misc queries) 1 July 27th 05 09:37 PM
what happens if I open an excel document in word? Emily Excel Discussion (Misc queries) 3 April 2nd 05 10:49 AM


All times are GMT +1. The time now is 11:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"