Results 1 to 4 of 4

Thread: [RESOLVED] VB.NET application with late binding - add table in a Word template at bookmark pos

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2013
    Posts
    134

    Resolved [RESOLVED] VB.NET application with late binding - add table in a Word template at bookmark pos

    Hi!

    I can't find a solution, so I hope to get some help on this.
    I have a VB.NET application, where I create a report using a Word template, that I fill out programmatically.
    While I was using early binding, everything worked fine, but now I have to switch to late binding, so the application can be used with different office versions.
    Currently I get this error:
    'Range' is not a by reference property.
    on this code:
    Code:
    oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("myTableBookmark").Range, rCount + 2, colCount)
    How can I place the table at a specific bookmark position in the word template using late binding in my application?

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VB.NET application with late binding - add table in a Word template at bookmark p

    try setting the target range to an object prior to adding the table
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2013
    Posts
    134

    Re: VB.NET application with late binding - add table in a Word template at bookmark p

    Thank you very much, this worked perfectly:
    Code:
    Dim tgRange As Object
    tgRange = oDoc.Bookmarks.Item("myBookmark").Range
    oTable = oDoc.Tables.Add(tgRange, rCount + 2, colCount)
    Besides, I could not find a reference, where all Word builtin property constants would be listed with their corresponding integer values.
    As with late binding this does not work
    Code:
    oTable.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter
    as there is no Word namespace avaliable, and the constant "WdParagraphAlignment.wdAlignParagraphCenter" is unknown, then I printed out the integer values while using early binding and now when using late binding I set the properties by their integer values like this:
    Code:
     oTable.Range.ParagraphFormat.Alignment = CInt(1)
    "WdParagraphAlignment.wdAlignParagraphCenter" = 1
    "WdParagraphAlignment.wdAlignParagraphRight" = 2
    "WdLineStyle.wdLineStyleSingle" = 1

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 2013
    Posts
    134

    Re: VB.NET application with late binding - add table in a Word template at bookmark p

    Edit: this was a doublepost, sorry.
    Last edited by AndyLD; May 26th, 2013 at 01:34 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width