none
The following code is not working. I want to extract pages from a Microsoft Word document. RRS feed

  • Question

  • Sub mcrExtractPages()
    Application.Browser.Target = wdBrowsePage
    For i = 1 To ActiveDocument.BuiltInDocumentProperties("Number of Pages")
      ActiveDocument.Bookmarks("\page").Range.Copy
      Documents.Add
      Selection.Paste
      ChangeFileOpenDirectory "C:\NGI"
      DocNum = DocNum + 1
      ActiveDocument.SaveAs FileName:="dumdum" & DocNum & ".docx"
      ActiveDocument.Close
    Next i
    End Sub
    • Moved by KareninstructorMVP Thursday, September 26, 2019 2:10 PM moved from vb.net forum
    Wednesday, September 25, 2019 1:25 PM

All replies

  • Hello,

    Is this code in a VB.NET project or in a Word macro?  If this is not VB.NET I can move your question to the proper forum.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, September 25, 2019 2:30 PM
  • Is it from Word Macro?  
    Wednesday, September 25, 2019 3:00 PM
  • Is it from Word Macro?  

    Hi,

    Why do you ask that?

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Thursday, September 26, 2019 8:59 AM
  • The code failed to extract the pages I expected. 
    Thursday, September 26, 2019 1:27 PM
  • Is it from Word Macro?  

    Hi,

    Why do you ask that?

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Many reasons, for instance ActiveDocument property if used say in VB6 or VB.NET would have a parent class as here it's similar to this.ActiveDocument, similarly Application.Browser.Target. It's obviously a macro/vba code yet rather than assume as just about anything is possible (like an Office add-in) ask the question. 


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, September 26, 2019 1:48 PM
  • Yes, it is from MS Word macro (MS Visual Basic for Application -Normal).  Press ALT-F11 in a document, a window pops up then paste the code & run (F5).
    Thursday, September 26, 2019 1:52 PM
  • https://smallbusiness.chron.com/extract-pages-microsoft-word-document-46792.html

    The code is from the link above.

    Thursday, September 26, 2019 1:57 PM
  • Yes, it is from MS Word macro (MS Visual Basic for Application -Normal).  Press ALT-F11 in a document, a window pops up then paste the code & run (F5).
    Since this is not VB.NET and is VBA for Word I'm moving your question o the Word for developer forum.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, September 26, 2019 2:09 PM