Hello!
I want to open a word doc from VB and put some text and save it. Can anybody tell me how this can be achieved?
Thanks,
Printable View
Hello!
I want to open a word doc from VB and put some text and save it. Can anybody tell me how this can be achieved?
Thanks,
'not sure how you want to do it
'here is one way
'you can shell word and then put your stuff in and save on
close
Private Sub Command1_Click()
Shell "C:\Program Files\Microsoft Office\Office\WINWORD.EXE", 1
End Sub
Here is some code I've saved from previous answers to questions here:
Dim WordApp As Word.Application
Dim WordRange As Word.Range
Dim nCount As Integer: Dim x As Integer
Dim nlRangeStart As Long
'Starting Word
Set WordApp = New Word.Application
WordApp.Application.Visible = True
WordApp.Documents.Add
Set WordRange = WordApp.ActiveDocument.Range
WordRange.Font.Size = 22
WordRange.InsertAfter "1-Name" & vbCrLf
WordRange.InsertAfter "2-Address" & vbCrLf
WordRange.InsertAfter "3-City" & vbCrLf
For x = 1 To 5
WordRange.InsertAfter " " & vbCrLf 'empty line
Next x
WordApp.ActiveDocument.SaveAs ("Path and Filename")
WordApp.Documents.Close (wdDoNotSaveChanges)
WordApp.Quit
Set WordApp = Nothing
Thanks Guys for your reply
Ganraj
does it need to be a word doc?