Re: Using Bookmarks for SaveAs File Name by philr
philr
Mon Oct 18 14:47:08 CDT 2004
Thanks Jonathan,
I created the macro and assigned a key within my new template. When I start
the recorder it procedes fine but I get stuck since I cannot stop the
recorder with the saveAs dialog open. Here I'm recording the macro for
encrypting the file using the SaveAs db. It runs through fine but when I
want to add in the concatenated file name and change the directory, it
doesn't save the macro since I have to change file type to .doc.
When I finish the encryption part of the macro my choice is Save or Cancel.
If I Cancel, my encryption setting will not be accepted. If I choose Save, it
wants to save the template, if I save and change file type to .doc the macro
is lost.
I'm hopeing for a macro that will allow me to encrypt and save (at a
prespecified location) in one step using information from earlier entered
bookmarks in a Userform as the fileName. Should I create the macro as 2
parts? 1st with encryption, close db then 2nd do the save As? I assume with
the last .Show the SaveAs db remains open for the user to press save?
Don't want to make this email too long, but my macro code follows.
' Encrypt_Save Macro
' Macro recorded 10/18/2004 by Phil
'
ActiveDocument.SetPasswordEncryptionOptions PasswordEncryptionProvider:= _
"Microsoft Enhanced Cryptographic Provider v1.0", _
PasswordEncryptionAlgorithm:="RC4",
PasswordEncryptionKeyLength:=128, _
PasswordEncryptionFileProperties:=True
With ActiveDocument
.ReadOnlyRecommended = True
.Password = "jra"
.WritePassword = "jra"
.RemovePersonalInformation = False
.RemoveDateAndTime = False
End With
With Options
.WarnBeforeSavingPrintingSendingMarkup = False
.StoreRSIDOnSave = True
.ShowMarkupOpenSave = True
End With
WithActiveDocument.Bookmarks
strFileName = .Item("NameLFM").Range.Text
strFileName = strFileName & "_" & .Item("MRN").Range.Text
strFileName = strFileName & "_" & .Item("DOV").Range.Text
End With
ChangeFileOpenDirectory "C:\aTemp\"
With Dialogs(wdDialogFileSaveAs)
.Name = strFileName
.Show
End With
ActiveDocument.SaveAs FileName:="C:\aTemp\Peds Rheum Template
10-18.dot", _
FileFormat:=wdFormatTemplate, LockComments:=False, Password:="jra", _
AddToRecentFiles:=True, WritePassword:="jra",
ReadOnlyRecommended:=True, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False,
SaveFormsData _
:=False, SaveAsAOCELetter:=False
End Sub
2 - Since my passwords are exposed you mentioned in your last message: "Not
really, but you can obfuscate it, by building the string out of widely
separated elements. " How's that?
Thanks, Phil
"Jonathan West" wrote:
>
> "philr" <philr@discussions.microsoft.com> wrote in message
> news:7CEDCBB9-BD47-432D-94EA-C6D619A1F511@microsoft.com...
> > RE: Word 2003
> > Iâ??ve created several bookmarks for my Word UserForm. When I create a new
> > document based on my template, my dialog box opens asks for patientName,
> > PatientID, clinicDate. On command it fills in the corresponding bookmarks
> > correctly.
> >
> > I want to use these same fields such that on saving the document it uses
> > these 3 same fields (concatenated) as the file name to be stored at a
> > remote
> > site. (The remote site remains constant and is located on the Save As
> > dialog
> > box.)
> >
> > I would like to do this as a macro and assign it to a key-combination. I
> > donâ??t know how to place these bookmark values into the file name box of
> > the
> > Save As dialog box. (Name, ID, and Date change with each file.)
>
> You could do something like this
>
> With ActiveDocument.Bookmarks
> strFileName = .Item("Name").Range.Text
> strFileName = strFileName & "-" & .Item("ID").Range.Text
> strFileName = strFileName & "-" & .Item("Date").Range.Text
> End With
>
> With Dialogs(wdDialogFileSaveAs)
> .Name = strFileName
> .Show
> End With
>
> Obviously, you may want to build the filename differently, but this
> demonstrates the concept.
>
> >
> > Related Question: I know itâ??s bad practice but I would like to encrypt the
> > file just before saving it using the macro. The macro for this works
> > fine,
> > but the template obviously exposes the encryption password. Can I encrypt
> > the template?
>
> Not really, but you can obfuscate it, by building the string out of widely
> separated elements. Then at least somebody looking through the template with
> a hex editor won't come across an obvious password. But this is only a
> defense against casual snooping and shouldn't be regarded as proof against a
> determined attack.
>
> Word is inherently insecure. Therefore, if you need the template password to
> be secure, then you need to ensure the security of the machine on which the
> template resides. That is somewhat beyond the scope of this group.
>
>
> --
> Regards
> Jonathan West - Word MVP
> www.intelligentdocuments.co.uk
> Please reply to the newsgroup
>
>