• Copy/paste within single doc (vbscript/Word/2ksr1)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Copy/paste within single doc (vbscript/Word/2ksr1)

    Author
    Topic
    #384552

    [edit to change ActiveDocument to ActiveWindow–that’s what I get for not cutting/pasting]

    As a follow up question to my last post:

    I have a document. Depending on a variable n, I need to copy the entire contents of the document, go to the end of the document, insert a page break, and paste the contents of the clipboard. Basically, I’m filling in some default information on a template, copying the default info, and then pasting it n times (in the same document). The code that launches this process is vbscript in an Outlook form.

    This is where I am so far:

    ‘I’ve launched Word, created the new doc based on the template (as objDoc), and filled in the default info

    ‘copy the whole document at this point
    objDoc.Select
    objDoc.ActiveWindow.Selection.Copy

    n = 1 ‘starting on the first evaluation

    Do until rItem is nothing

    ‘check which item we’re on
    If n=1 then
    ‘do nothing, there is only one item
    Else
    objDoc.ActiveWindow.Selection.WholeStory
    objDoc.ActiveWindow.Selection.EndKey unit:=wdStory ‘***
    objDoc.ActiveWindow.Selection.InsertBreak Type:=wdPageBreak
    objDoc.ActiveWindow.Selection.Paste

    End If

    ‘do my other stuff here

    n=n+1

    Loop

    I get a “expected statement” error at the line ending with ‘***

    This does not seem like it should be complicated, but I am at a complete loss. I am hoping it is just something stupid that I’m missing. Any thoughts would be appreciated…thanks in advance.

    jen

    Viewing 0 reply threads
    Author
    Replies
    • #660171

      If you’re using late binding, you can’t use constants like wdStory and wdPageBreak. Try their numeric values 6 and 7, respectively.

      • #660273

        Oh good grief.

        That did it. The stupid thing is, I *knew* that–I’ve been looking up numerical values for constants for other parts of the code for a few days now.

        Thanks!

    Viewing 0 reply threads
    Reply To: Copy/paste within single doc (vbscript/Word/2ksr1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: