Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
I forgot my password to open an excel document, how do I open it? | Excel Discussion (Misc queries) | |||
change excel document into word document | Excel Discussion (Misc queries) | |||
Open A Word Document from Excel | Excel Programming | |||
How to change a excel document into a word document? | Excel Discussion (Misc queries) | |||
what happens if I open an excel document in word? | Excel Discussion (Misc queries) |