Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   Excel macro issue to cut and paste sections inside word (http://www.go4expert.com/forums/excel-macro-issue-cut-paste-sections-t8863/)

KLaminero 16Feb2008 00:06

Excel macro issue to cut and paste sections inside word
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:


# '-----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


'-----Create personalized tuning procedure
Set appWD_tun_process = CreateObject("Word.Application" )
appWD_tun_process.Visible = True

Set S = appWD_tun_process.ActiveWindow.Selection

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:


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


  1. Set S = appWD_tun_process.ActiveWindow.Selection
  2. With S
  3.    Selection.Words(1).Delete
  4. End With


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" )

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


All times are GMT +5.5. The time now is 11:05.