View Single Post
 
Old 06-02-2016, 09:11 AM
Greengecko Greengecko is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Sep 2014
Posts: 7
Greengecko is on a distinguished road
Default Import a specific range (bookmarked section) from all Word docs in a selected folder

Hello,
I'm not a VBA programmer; I do know a fair amount of javascript. Is there a way that the above script can be modified to import a specific range (bookmarked section) from all Word docs in a selected folder? I'd greatly appreciate any help. Here's my first attempt at it. What I'm trying to do is select all files in the folder selected by the user, then import all files in that folder, selecting the Range (bookmark) "pmo":


Option Explicit
Sub Importer()
Dim myFolder As String
Dim myFile As String
Dim wdDoc As Document
Dim docmFiles As Document

Application.ScreenUpdating = False

myFolder = openFolder

If myFolder = "" Then Exit Sub

myFile = Dir(myFolder & "\*.docm", vbNormal)
Set wdDoc = ActiveDocument

While myFile <> ""

With Selection.Find.Text = "pmo"
End With
Selection.MoveDown Unit:=wdLine, Count:=1

Set docmFiles = Documents.Open(FileName:=myFolder & "\" & myFile, AddToRecentFiles:=False, Visible:=False, ConfirmConversions:=False)
wdDoc.Range.InsertAfter docmFiles.Range.Bookmarks.Item("pmo") & vbCr
docmFiles.Close SaveChanges:=True


myFile = Dir()
Wend

Set docmFiles = Nothing
Set wdDoc = Nothing

Application.ScreenUpdating = True
End Sub
Function openFolder() As String

Dim oFolder As Object

openFolder = ""

Set oFolder = CreateObject("Shell.Application").BrowseForFolder( 0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then openFolder = oFolder.Items.Item.Path

Set oFolder = Nothing
End Function

Last edited by Greengecko; 06-02-2016 at 09:44 AM. Reason: added VBA script
Reply With Quote