Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert new line (word)

Status
Not open for further replies.

Pegasus0990

Technical User
Joined
Nov 16, 2006
Messages
27
Location
US
Hi, I am working on a program that pulls data from Excel into a Word document. However, IOT complete this, I need to be able to insert blank lines between values from the cells I pull. I am pulling the data by using bookmarks.

Does anybody know how to write VB code in Word thats function is basically 'pressing the enter key' automatically when i want it to??

Thank you for your help.
 
I have two questions and they are down below and can be noticed by the ///// just before it.


Public Sub CommandButton1_Click()
HideListBoxes

Dim oDoc As Word.Document

Set oDoc = Application.Documents("C:\worddoc.doc")

Dim oExcel As Excel.Application, myWB As Excel.Workbook

Set oExcel = New Excel.Application
Set myWB = oExcel.Workbooks.Open("C:\excelfile.xls")

Dim b As Integer

///// for some reason my loop is not outputing anything, however if i can "b" to an integer such as 22 then it will do what it is suppose too/////

b = (myWB.Sheets("Questions").Range("B20").Value)

For i = 20 To b
oDoc.Bookmarks("bookmark1").Range.Text = myWB.Sheets("Questions").Cells(i, 1).Value

/////here i am looking for the way to insert a line so that i can separate each output in Word/////
Next i

Set myWB = Nothing
End Sub
 
You could try something like:

(not tested)

[tt]b = CType(myWB.Sheets("Questions").Range("B20").Value, integer)[/tt]

[tt]oDoc.Bookmarks("bookmark1").Range.Text = myWB.Sheets("Questions").Cells(i, 1).Value.ToString + Environment.Newline[/tt]


Hope this helps.



[vampire][bat]
 
neither worked.

question for you

what is CType? it is not coming up in my VB, and nor is Environment.

I am looking as "writeblankline" but im kinda confused with the syntax of what is going on. any idea how i would do this? here is an example.

Function WriteBlankLinesToFile

ForWriting = 2

Dim fso, f

Set fso = CreateObject("Scripting.FileSystemObject")

Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)

f.WriteBlankLines 2

End Function
 
I have the new line infomation resolved now with simple command of vbnewline, haha so easy ;)

but still no idea about why my "b" value in my loop is not working.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top