How to assign password for output to command

T

Tim

Hi guys,

I currently using the following command to output my
report.

DoCmd.OutputTo acReport, "TableB", "RichTextFormat
(*.rtf)", "c:\temp\test.doc", False, ""

Is it possible to add password to "c:\temp\test.doc"?

Thanks in advance.

Tim.
 
T

TC

You would have to do this by starting an instance of Word, then using Word
VBA commands to open the document & establish the password.

Something like this (untested):

dim oWord as object
set oWord = createobject ("word.application")
oWord.visible = true
oWord.open "C:\temp\test.doc"
[ set password here ]
oWord.close
oWord.quit
set oWord = nothing

Look at the Word VBA help to find the appropriate Word VBA command(s) to set
the password.

HTH,
TC
 
T

Tim

Hi TC,

Thanks you for your response. I tried the code but I
couldn't figure how to add the password. Could you help
me again?

Public Sub test()

Dim oWord As Object

set oWord = createobject ("word.application")
oWord.Visible = true
oWord.Documents.open "C:\temp\test.doc"
'How To Add password

oWord.ActiveDocment.Close
oWord.Quit
set oWord = Nothing

End Sub

Thanks.

Tim.

-----Original Message-----
You would have to do this by starting an instance of Word, then using Word
VBA commands to open the document & establish the password.

Something like this (untested):

dim oWord as object
set oWord = createobject ("word.application")
oWord.visible = true
oWord.open "C:\temp\test.doc"
[ set password here ]
oWord.close
oWord.quit
set oWord = nothing

Look at the Word VBA help to find the appropriate Word VBA command(s) to set
the password.

HTH,
TC


Tim said:
Hi guys,

I currently using the following command to output my
report.

DoCmd.OutputTo acReport, "TableB", "RichTextFormat
(*.rtf)", "c:\temp\test.doc", False, ""

Is it possible to add password to "c:\temp\test.doc"?

Thanks in advance.

Tim.


.
 
T

TC

I don't have Word on this PC, to check.

However, you might try this at the line in question:

oWord.ActiveDocument.Password = "645bn&#$z!" ' <- the password.

HTH,
TC


Tim said:
Hi TC,

Thanks you for your response. I tried the code but I
couldn't figure how to add the password. Could you help
me again?

Public Sub test()

Dim oWord As Object

set oWord = createobject ("word.application")
oWord.Visible = true
oWord.Documents.open "C:\temp\test.doc"
'How To Add password

oWord.ActiveDocment.Close
oWord.Quit
set oWord = Nothing

End Sub

Thanks.

Tim.

-----Original Message-----
You would have to do this by starting an instance of Word, then using Word
VBA commands to open the document & establish the password.

Something like this (untested):

dim oWord as object
set oWord = createobject ("word.application")
oWord.visible = true
oWord.open "C:\temp\test.doc"
[ set password here ]
oWord.close
oWord.quit
set oWord = nothing

Look at the Word VBA help to find the appropriate Word VBA command(s) to set
the password.

HTH,
TC


Tim said:
Hi guys,

I currently using the following command to output my
report.

DoCmd.OutputTo acReport, "TableB", "RichTextFormat
(*.rtf)", "c:\temp\test.doc", False, ""

Is it possible to add password to "c:\temp\test.doc"?

Thanks in advance.

Tim.


.
 
T

Tim

Hi TC,

I tried the command but it doesn't work.

Thanks for your time.

Tim.
-----Original Message-----

I don't have Word on this PC, to check.

However, you might try this at the line in question:

oWord.ActiveDocument.Password = "645bn&#$z!" ' <- the password.

HTH,
TC


Tim said:
Hi TC,

Thanks you for your response. I tried the code but I
couldn't figure how to add the password. Could you help
me again?

Public Sub test()

Dim oWord As Object

set oWord = createobject ("word.application")
oWord.Visible = true
oWord.Documents.open "C:\temp\test.doc"
'How To Add password

oWord.ActiveDocment.Close
oWord.Quit
set oWord = Nothing

End Sub

Thanks.

Tim.

-----Original Message-----
You would have to do this by starting an instance of Word, then using Word
VBA commands to open the document & establish the password.

Something like this (untested):

dim oWord as object
set oWord = createobject ("word.application")
oWord.visible = true
oWord.open "C:\temp\test.doc"
[ set password here ]
oWord.close
oWord.quit
set oWord = nothing

Look at the Word VBA help to find the appropriate Word VBA command(s) to set
the password.

HTH,
TC


Hi guys,

I currently using the following command to output my
report.

DoCmd.OutputTo acReport, "TableB", "RichTextFormat
(*.rtf)", "c:\temp\test.doc", False, ""

Is it possible to add password to "c:\temp\test.doc"?

Thanks in advance.

Tim.


.


.
 
T

Tim Ferguson

PMFJI

I tried the command but it doesn't work.
This is from Word help on the Open method:

Syntax 1

expression.Open(FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,
PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument,
WritePasswordTemplate, Format, Encoding, Visible)

....

PasswordDocument Optional Variant. The password for opening the document.

PasswordTemplate Optional Variant. The password for opening the template.


Hope that helps


Tim F
 
T

TC

FFTJIWUL!

But, he wants to *add* a password to his files. Your syntax is for opening a
file with an existing password.

To the original poster: what do you mean, "it doesn't work"? What error
message did you get?

TC

FFTJIWUL: feel free to jump in whenever you like!
 
T

Tim

Hi TC,

I didn't get any error message. The code didn't add the
password to my file.

Thanks.

Tim.
 
T

Tim Ferguson

TC said:
FFTJIWUL!

Okay, I give up -- what does that mean?
But, he wants to *add* a password to his files. Your syntax is for
opening a file with an existing password.

Speedreading again..., try the SaveAs method:

Saves the specified document with a new name or format. The arguments for
this method correspond to the options in the Save As dialog box (File
menu).

Syntax

expression.SaveAs(FileName, FileFormat, LockComments, Password,
AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts,
SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter)

....

Password Optional Variant. A password string for opening the document.


Have to admit, though, that I didn't know about the Password property until
I just looked it up. Learn something every day... :)

All the best


Tim F
 
T

Tim

Tim F

The command line worked, but it didn’t save to c:\temp.
It saved to word’s default folder. Do you know how to
save to c:\temp (My original folder).

Thanks.

Tim.
 
T

TC

It should work as long as you "save as" to the full file path name:
C:\blah\my.doc, or whatever it was. If you just "save as" to a simple name
like my.doc, it will probably just go to a default folder.

HTH,
TC
 
T

TC

Tim Ferguson said:
Okay, I give up -- what does that mean?


You said PMFJI, which I didn't know. I was about to ask, when I realized
what it meant. So I made up a new one to get back at you! - but I did put
its meaning further down in my post:

Feel Free To Jut In Any Time yoU Want!

:)

TC
 
T

Tim

Hi TC,

After I changed the command line, it didn't add password
to my file. Please help.

oWord.ActiveDocument.SaveAs
FileName:="c:\TempDoc\test.doc",
FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="123",
AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False,
SaveFormsData:=False, _
SaveAsAOCELetter:=False

Thanks a lot.

Tim
 
T

Tim Ferguson

After I changed the command line, it didn't add password
to my file. Please help.

oWord.ActiveDocument.SaveAs _
FileName:="c:\TempDoc\test.doc", _
FileFormat:=wdFormatDocument, _
LockComments:=False, _
Password:="123", _
AddToRecentFiles:=True, _
WritePassword:="", _
ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:= False, _
SaveNativePictureFormat:=False, _
SaveFormsData:=False, _
SaveAsAOCELetter:=False


From what you posted, it's impossible to tell what is part of the command
and what isn't. I've guessed where the line continuation characters ought
to be. It's probably a good idea to remove all the parameters you don't
need like FileFormat, LockComments and so on, because there are so many
trees here you cannot see the wood. You don't need any more than

oWord.ActiveDocument.SaveAs _
FileName:="c:\TempDoc\test.doc", _
Password:="123"


Hope that helps


Tim F
 
T

Tim

Hi Tim F,

I tried your command. It didn't add password to my file
either. Do you have any idea?

Thanks a lot.

Tim.
 
T

Tim Ferguson

TC said:
Maybe try asking in one of the microsoft.public.word.* newsgroups.

If you think you've found an undocumented feature (ahem) in the .SaveAs
method, then I agree that's probably the best place to go next. It's not an
Access problem!!

B Wishes


Tim F
 
T

Tim

TC and Tim F,

I got the help form word newsgroup. The problem was
solved.

Thanks for your help again.

Tim.
 
T

Tim Ferguson

I got the help form word newsgroup. The problem was
solved.

Okay, good. By the way, I tried the command in Word myself and it works for
me as advertised.

All the best


Tim F
 

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

Top