Not a Member Yet,
Click here to Register

ID: 436
Viewed: 3658
Added: Aug 19, 2002
Version:
Snippet uploaded by: snippet
Written By: Unknown
Demo: Sorry, no demo



User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

Saves to word and has formatting with columns

Highlight all by clicking in box
<!---Declaration--->
none

Highlight All
<!---Code--->
Public Function WordDoc(sFileName As String, sNewDoc As String) As String
'Open the text file into word and save it as a word doc behind the scenes
Dim objWord As Object
Dim objDoc As Object
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(sFileName)
objWord.Selection.WholeStory
objDoc.SaveAs sNewDoc, 0 'wdFormatDocument
objDoc.Close
objWord.Quit

'clear memory of the objects
Set objDoc = Nothing
Set objWord = Nothing
'remove this...
MsgBox "Mission Accomplished"
End Function


Private Sub Command1_Click()
Dim strbuild As String
Dim mySpace As Integer
'split the textbox data
a1 = Split(Text1.Text, vbCrLf)
a2 = Split(Text2.Text, vbCrLf)
'get info as to which side will have more content
a1max = UBound(a1)
a2max = UBound(a2)
'if side 2 > side one
If a1max < a2max Then
For i = 0 To UBound(a2)
If i <= UBound(a1) Then
mySpace = Len(a1((i)))
mySpace = (36 - mySpace)
Else
mySpace = 36
End If
If i <= UBound(a1) Then
strbuild = strbuild & a1(i) & Space(mySpace) & a2(i) & vbCrLf
Else
strbuild = strbuild & (Space(mySpace)) & a2(i) & vbCrLf
End If
Next i
Else
'if side one > side 2 then
' commented the lines to it wouldn't save twice.

For i = 0 To UBound(a1)
' If i <= UBound(a2) Then
' mySpace = Len(a1((i)))
' mySpace = 36 - mySpace

' strbuild = strbuild & a1(i) & (Space(mySpace)) & a2(i) & vbCrLf
' End If
If i > UBound(a2) Then
strbuild = strbuild & a1(i) & vbCrLf
End If
' If i > a2max Then
' strbuild = strbuild & vbCrLf & a1(i)
' End If
Next i

End If

'build string to load into text file
strmsg = lab & vbTab & recname & vbCrLf & vbNewLine & strbuild
Open "C:my documentsmyfile.txt" For Output As #1
Print #1, strmsg
Close #1
'convert it to a word document
'pass it the name of the text file and the filename you want it saved as
Call WordDoc("C:my documentsmyfile.txt", "C:my documentsNewDoc.doc")
End Sub

Private Sub Form_Load()
'give it some dummy information for this exercise
Text1 = ""
Text2 = ""
Text1 = "watermelon" & vbCrLf & "carrots" & vbCrLf & "potatoe" & vbCrLf & "onion" & vbCrLf & "custard"
Text2 = "1 cup" & vbCrLf & "blender" & vbCrLf & "work will you."
End Sub;


No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2024 snippetlibrary.com All Rights Reserved. Conditions
Do NOT follow this link or you will be banned from the site!