Excel macro issue to cut and paste sections inside word

Discussion in 'Visual Basic ( VB )' started by KLaminero, Feb 15, 2008.

  1. KLaminero

    KLaminero New Member

    Joined:
    Nov 17, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Hi all,

    I am trying to create an automatically customized word document based on the user's answers to an excel sheet.
    Based on a master document and on the answers, I want to insert the appropriate parts of the master doc in the customized one. For that I use an excel macro that collects the answers.
    I have been able to copy and paste the entire document (using wholestory) but I am completely unable to do the same with sections.
    Here is what i have so far:

    Code:
    # '-----Copy master doc
    # Set appWD_master_doc = CreateObject("Word.Application" )
    # appWD_master_doc.Visible = False
    # appWD_master_doc.Documents.Open Filename:="Q:\Sea_Trials_Notes.doc", ReadOnly:=True
    # appWD_master_doc.Selection.WholeStory
    # appWD_master_doc.Selection.Copy
    

    Code:
    '-----Create personalized tuning procedure
    Set appWD_tun_process = CreateObject("Word.Application" )
    appWD_tun_process.Visible = True
    appWD_tun_process.Documents.Add
    
    Set S = appWD_tun_process.ActiveWindow.Selection
    appWD_tun_process.Selection.Paste
    

    And here is where the problems start. So far I have just been trying with a hardcoded section. Here are a few of the unsuccessful ways i tried this:

    Code:
    Dim MyRange   As Range
    Set MyRange = ActiveDocument.Sections(1).Range
    Set MyRange = MyRange.GoTo(What:=wdGoToSections, Name:="1" )
    appWD_tun_process.Selection.Delete
    

    Code:
       1. Set S = appWD_tun_process.ActiveWindow.Selection
       2. With S
       3.     Selection.Words(1).Delete
       4. End With
    
    Code:
    Dim MyRange As Range
    Set MyRange = appWD_tun_process.Selection.Range
     Set MyRange = MyRange.GoTo(What:=wdGoToPage, Name:="2" )
    Set MyRange = MyRange.GoTo(What:=wdGoToBookmark, Name:="\page" )
    MyRange.Delete''
    

    Does somebody have any idea on the correct way to do this?

    Thanks
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice