Insert 2/3 blank lines in Word and select the last line

drom

Well-known Member
Joined
Mar 20, 2005
Messages
528
Office Version
  1. 2021
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Hi and Thanks in advance!

I have the following lines of code:
VBA Code:
  Dim WordApp As Object:                  Set WordApp = GetObject(, "Word.Application")
  Dim WordDoc As Object
  Dim WordRng As Object                     'Word.Range
  Dim objSelection
  If WordApp Is Nothing Then
    Set WordApp = CreateObject("Word.Application")
  End If
    WordApp.Visible = True
    Set WordDoc = WordApp.Documents.Add
    WordDoc.Select

  Set objSelection = WordApp.Selection

   objSelection.TypeText ("This is my text in Word Document using Excel") & Chr(10) & Chr(10)

But If I open a blank word document (my intention is to insert a few object like a chart, a table a few lines of text etc...)

So after I have the blank word document open and selected... (I know this)
  • If I insert a Chart ("I CAN do it, works fine)

My question:
  • How can I insert after the inserted chart, table...
    • 2/3 blank lines and select the last line?

Thanks again
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi drom. It seems like U want to insert 2 or 3 "lines" in the document not 2/3 of a line.... so you can trial either adding CHR(13) which is a blank paragraph or objSelection.typeparagraph several times. To select the last line maybe....
Code:
objSelection.Paragraphs.Count.Select
or
Code:
LastParaLoc = WordApp.Selection.Paragraphs.Count 'last paragraph(line#)
LastParaLoc.Select
HTH. Dave
 
Upvote 0
Solution
LastParaLoc = WordApp.Selection.Paragraphs.Count 'last paragraph(line#) LastParaLoc.Select


Yes:
'Last One
WordDoc.Paragraphs.Last.Range.Select
'Select la 4th line
WordDoc.Paragraphs(4).Range.Select
 
Upvote 0

Forum statistics

Threads
1,215,436
Messages
6,124,867
Members
449,192
Latest member
MoonDancer

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top