hn4u @ Last updated 21/11/04 22:42
Go to my homepage at http://4u.jcisio.com
Full version available at http://4u.jcisio.com/r/article377.htm

Không rõ

Chuyển một tập tin text thành một tập tin word có password. (VB)

Bạn sẽ có thể chuyển một tập tin text thành một tập tin word có password. Một cách để bạn giao tiếp với Word thông qua đối tượng bằng ngôn ngữ VB

Chúng ta sẽ mở tập tin BigText và chuyển thành BigText.doc và có password bảo vệ là 'enter'. (Bạn tạo tập tin text bigtext trước). Tạo một dự án VB6 và sử dụng các dòng code sau:

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

On Error Resume Next

Set wdA = GetObject(, ''Word.Application'')

If Err = 429 Then

Err.Clear

Set wdA = CreateObject(''Word.Application'')

If Err = 429 Then ' Không tìm thấy Word

MsgBox ''Word not available''

Err.Clear

Exit Sub

End If

End If

WkDir = App.Path

Destination = WkDir & ''\'' & ''BigWord.doc''

If Dir$(Destination) <> '''' Then

MsgBox Destination & '' bị trùng''

GoTo ErrEnd

End If

Source = WkDir & ''\'' & ''BigText''

Set wdD = wdA.Documents.Open(Source)

If wdD = Null Then

MsgBox ''There must be a file called 'BigText' in '' & WkDir

GoTo ErrEnd

End If

wdD.SaveAs FileName:=Destination, FileFormat:=0, Password:=''enter''

wdD.Close

MsgBox ''Tập tin'' & Destination & ''  được tạo''

ErrEnd:

wdA.Quit

Set wdD = Nothing

Set wdA = Nothing

End Sub


hainam4u @ Last updated 21/11/04 22:42
Go to my homepage at http://4u.jcisio.com