Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 612
  • Last Modified:

How to :Insert Word Table into Word Bookmark

I have Word document with default Bookmark
Simply I wanr to replace this bookmark with dynammic ms Word table that I populated using VB 6

Here is my Code

Dim docNew As Word.Document
 Dim tblNew As Table
Dim docApp As Word.Application
Dim docSave As Word.Document
Dim intX As Integer
Dim intY As Integer

    Set docApp = CreateObject("Word.Application")
    Set docSave=docApp.Documents.Open("C:\temp\new.doc")
    Set docNew = Documents.Add
    Set tblNew = docNew.Tables.Add(Selection.Range, 3, 5)
    With tblNew
    For intX = 1 To 3
        For intY = 1 To 5
            .Cell(intX, intY).Range.InsertAfter "Cell: R" & intX & ", C" & intY
        Next intY
    Next intX
    .Columns.AutoFit
    End With

' This Part does not wok. Once I populated tblNew I want to replace Bookmark with actual table
If (docSave.Bookmarks("OK").Name.Exists = True) Then
 .....
 Set docSabe.Bookmarks("OK").Range=TblNew.Range
End If

Range does not work for table
Plase advice

Regards
Alex

   
0
Saltebor
Asked:
Saltebor
1 Solution
 
aeklundCommented:
' This Part does not wok. Once I populated tblNew I want to replace Bookmark with actual table
If (docSave.Bookmarks.Exists("OK") = True) Then
  tblNew.Select
  Selection.Copy
  docSave.Bookmarks("OK").Select
  Selection.Paste
End If


Above is modified code to perform what you are asking for... to verify the change, add this line to make word visisble and you will see the changes:

docApp.Visible = True
0
 
CleanupPingCommented:
Saltebor:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
DanRollinsCommented:
Moderator, my recommended disposition is:

    Accept aeklund's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now