Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 06-06-2016, 05:52 AM
Greengecko Greengecko is offline Import a specific range (bookmarked section) from all Word docs in a selected folder Windows 7 64bit Import a specific range (bookmarked section) from all Word docs in a selected folder Office 2010 64bit
Novice
Import a specific range (bookmarked section) from all Word docs in a selected folder
 
Join Date: Sep 2014
Posts: 7
Greengecko is on a distinguished road
Default Multiple bookmark ranges

Thanks for that, Paul. Now, if I want to insert a couple more bookmark ranges into the same doc, can I just repeat a section of that code and just change the bookmark? My attempt is below, just repeating the "With" section using another bookmark called "int" (thanks for the tip on code tags):

Code:
Sub Import_Bookmarked_Text()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, wdDocSrc As Document, wdDocTgt As Document
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
Set wdDocTgt = ActiveDocument
While strFile <> ""
  If strFolder & "\" & strFile <> wdDocTgt.FullName Then
  Set wdDocSrc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
  With wdDocSrc
    If .Bookmarks.Exists("pmo") Then
    wdDocTgt.Range.InsertAfter vbCr
    wdDocTgt.Range.Characters.Last.FormattedText = .Bookmarks("pmo").Range.FormattedText
    .Close SaveChanges:=False
  End With
  With wdDocSrc
    If .Bookmarks.Exists("int") Then
    wdDocTgt.Range.InsertAfter vbCr
    wdDocTgt.Range.Characters.Last.FormattedText = .Bookmarks("int").Range.FormattedText
    .Close SaveChanges:=False
  End With
  strFile = Dir()
Wend
Set wdDocSrc = Nothing: Set wdDocTgt = Nothing
Application.ScreenUpdating = True
End Sub
 
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Import a specific range (bookmarked section) from all Word docs in a selected folder How to Import range between two string from other document PRA007 Word VBA 1 12-18-2015 09:23 PM
Outlook VBA to move selected email to a public folder aaroncrt Outlook 2 10-21-2013 05:11 PM
Print attachment when it arrive in specific folder with specific subject visha_1984 Outlook 1 01-30-2013 10:42 AM
Returning a specific value when item is selected from a drop-down list J Press Excel 4 09-10-2012 06:12 AM
Import a specific range (bookmarked section) from all Word docs in a selected folder Printing specific section dfinch Word VBA 2 06-09-2011 05:10 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:22 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft