Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
COPY A TEXT FILE TO A PASSWORD PROTECTED WORD DOC....
Author:
Louis Delongchamp
E-mail:
Click to e-mail author
Website:
http://www.cyberbeach.net/~loudelon
Submitted:
8/9/2001
Version:
VB6
Compatibility:
VB6
Category:
File Manipulation
Views:
10777
COPY A TEXT FILE TO A PASSWORD PROTECTED WORD DOC. A program that utilises Word for Windows 2000 to open a file called 'BigText' gives the file the name 'BigWord.doc' and saves the file with the password 'enter'.
Declarations:
Make sure that the directory you are working in contains the file 'BigText' (See CONCATENATE TEXT FILES USING FSO) Make SURE the file 'BigWord.doc' does not already exist! Do not forget at the end to erase BigText and BigWord from your hard drive. Start a new VB6 project and place this code in the form.
Code:
Option Explicit Private Sub Form_Load() HideTextINWord End End Sub Private Sub HideTextINWord() Dim wdA As Object, wdD As Object Dim WkDir As String, Source As String, Destination As String ' Find Word On Error Resume Next ' Is it already open? Set wdA = GetObject(, "Word.Application") If Err = 429 Then Err.Clear ' No, then start Word Set wdA = CreateObject("Word.Application") If Err = 429 Then ' Sorry, could not find Word MsgBox "Word not available" Err.Clear Exit Sub End If End If ' Retrieve our current location on the hard drive WkDir = App.Path ' Name of the Destination document Destination = WkDir & "\" & "BigWord.doc" ' Check to see it does not already exists If Dir$(Destination) <> "" Then MsgBox Destination & " must not already exist" GoTo ErrEnd End If ' Name of the Source document Source = WkDir & "\" & "BigText" ' Open the Source with Word Set wdD = wdA.Documents.Open(Source) If wdD = Null Then MsgBox "There must be a file called 'BigText' in " & WkDir GoTo ErrEnd End If ' Create the Destination document and password protect it wdD.SaveAs FileName:=Destination, FileFormat:=0, Password:="enter" ' Close the document wdD.Close MsgBox "The document " & Destination & " is created" ErrEnd: ' Terminate Word wdA.Quit Set wdD = Nothing Set wdA = Nothing End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2023 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement