• Opening a blank Doc. (Word XP)

    Author
    Topic
    #386127

    In my macro, I copied some text, and I want to open a new document and past it/ manipulate it. Can that be done?
    I was able to record it as such, but when I ran the macro, all of the actions took place in the original document.

    Viewing 0 reply threads
    Author
    Replies
    • #668727

      That sound pretty simple, really. Copy text to the clipboard from one document
      then paste it into a new blank doc? Post your macro code. It might provide a clue.

      • #668733

        Here’s the code. I recorded it in 2000. ( I don’t think it should make a difference on this topic)

        I recorded most of the script and went back in to start commenting the sections. Fron what I can read in the code, it didn’t record anything that would have opened a new doc. You’ll see by my comment, where it’s supose to be. – J

        Sub RTMCreate4()

        ‘ RTMCreate4 Macro
        ‘ Macro recorded 4/15/2003 by SanBill

        Selection.EndKey Unit:=wdStory
        With ActiveDocument
        .TablesOfContents.Add Range:=Selection.Range, RightAlignPageNumbers:= _
        True, UseHeadingStyles:=True, UpperHeadingLevel:=4, _
        LowerHeadingLevel:=9, IncludePageNumbers:=False, AddedStyles:= _
        “Heading 1,1,Heading 2,2,Heading 3,3”, UseHyperlinks:=True, _
        HidePageNumbersInWeb:=True
        .TablesOfContents(1).TabLeader = wdTabLeaderDots
        .TablesOfContents.Format = wdIndexIndent
        End With
        Selection.Find.ClearFormatting
        Selection.Find.Style = ActiveDocument.Styles(“TOC 1”)
        Selection.Find.ParagraphFormat.Borders.Shadow = False
        With Selection.Find
        .Text = “”
        .Replacement.Text = “”
        .Forward = False
        .Wrap = wdFindAsk
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.MoveDown Unit:=wdParagraph, Count:=2, Extend:=wdExtend
        Selection.Fields.Unlink
        Selection.ConvertToTable Separator:=wdSeparateByTabs, NumColumns:=2, _
        NumRows:=20, Format:=wdTableFormatNone, ApplyBorders:=True, ApplyShading _
        :=True, ApplyFont:=True, ApplyColor:=True, ApplyHeadingRows:=True, _
        ApplyLastRow:=False, ApplyFirstColumn:=True, ApplyLastColumn:=False, _
        AutoFit:=True, AutoFitBehavior:=wdAutoFitContent
        Selection.MoveLeft Unit:=wdCharacter, Count:=1
        End Sub

        • #668734

          Hummm. I take that back, the code isn’t much help at this point. A little, I guess.

          Here’s some air code (heavy on the CO2) (see Rory, I like it so much I’m using it now!)
          Tell us if this is a correct interpretation of your intentions:

          1. Add a table of contents
          2. Select the table of contents using the find method
          3. Then copy that selected TOC to the clipboard
          4. Create new blank doc.
          5. Paste TOC from clipboard into new doc

          • #668737

            Yes… But I also want to manipulate it, once in the new doc.

            • #668739

              Meaning….?

              What do you want to do to the TOC in the new document?

            • #668742

              Select it, Break the link and convert it to a table.

              Though, that could be done in the current doc, cut and pasted into the new doc.

              Either way, when I open a new doc, the code for such doesn’t record. It picks back up where I paste (supposedly into the new doc)… but it pastes right into the same doc.

            • #668778

              Insert the instruction to create a new document after copying and before pasting:


              Selection.Copy

              ‘Open New document and paste.
              Documents.Add ‘ Creates a new doc and makes it the active doc.
              Selection.Paste

            • #668843

              That’s all it needed! Case Solved – Thank – You.

      • #668735

        OOOPS! I posted the wrong code… I think it’s similar, but this one at least has comments…

        Sub RTMCreate2()

        ‘ RTMCreate2 Macro
        ‘ Macro recorded 4/15/2003 by Jody Dyche

        ‘Go to beginning of document and go to beginning of TOC. Select TOC.
        Selection.HomeKey Unit:=wdStory
        Selection.Find.ClearFormatting
        Selection.Find.Style = ActiveDocument.Styles(“TOC 1”)
        Selection.Find.ParagraphFormat.Borders.Shadow = False
        With Selection.Find
        .Text = “”
        .Replacement.Text = “”
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend

        ‘Replace Existing TOC with 9 level TOC
        With ActiveDocument
        .TablesOfContents(1).Delete
        .TablesOfContents.Add Range:=Selection.Range, RightAlignPageNumbers:= _
        True, UseHeadingStyles:=True, UpperHeadingLevel:=4, _
        LowerHeadingLevel:=9, IncludePageNumbers:=False, AddedStyles:= _
        “Heading 1,1,Heading 2,2,Heading 3,3”, UseHyperlinks:=True, _
        HidePageNumbersInWeb:=True
        .TablesOfContents(1).TabLeader = wdTabLeaderDots
        .TablesOfContents.Format = wdIndexIndent
        End With

        ‘Go to beginning of document, Go to TOC, select and copy.
        Selection.HomeKey Unit:=wdStory
        Selection.Find.ClearFormatting
        Selection.Find.Style = ActiveDocument.Styles(“TOC 1”)
        Selection.Find.ParagraphFormat.Borders.Shadow = False
        With Selection.Find
        .Text = “”
        .Replacement.Text = “”
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
        Selection.Copy

        ‘Open New document and paste.
        Selection.Paste
        Selection.HomeKey Unit:=wdStory
        Selection.WholeStory
        Selection.Fields.Unlink
        Selection.ConvertToTable Separator:=wdSeparateByTabs, NumColumns:=2, _
        NumRows:=21, Format:=wdTableFormatNone, ApplyBorders:=True, ApplyShading _
        :=True, ApplyFont:=True, ApplyColor:=True, ApplyHeadingRows:=True, _
        ApplyLastRow:=False, ApplyFirstColumn:=True, ApplyLastColumn:=False, _
        AutoFit:=True, AutoFitBehavior:=wdAutoFitFixed
        Selection.HomeKey Unit:=wdLine
        Selection.MoveRight Unit:=wdCell
        Selection.HomeKey Unit:=wdLine
        Selection.HomeKey Unit:=wdStory
        End Sub

    Viewing 0 reply threads
    Reply To: Opening a blank Doc. (Word XP)

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

    Your information: