Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8663905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:06:30+00:00 2026-06-12T17:06:30+00:00

The macro I have in excel reads data from every row and creates a

  • 0

The macro I have in excel reads data from every row and creates a word file for each row based on that data. The word file used as a template has bookmarks (values in columns are mapped to the bookmarks).

I got it to work for one row, but it won’t loop through all the rows. The code I’m using I got from:http://www.wiseowl.co.uk/blog/s199/word-bookmarks.htm

Here is my code:

Option Explicit

'change this to where your files are stored

Const FilePath As String = "C:\Files\"

Dim wd As New Word.Application

Dim SOPCell As Range

Sub CreateWordDocuments()

    'create copy of Word in memory

    Dim doc As Word.Document

    wd.Visible = True

    Dim SOPRange As Range

    'create a reference to all the people

    Range("A1").Select

    Set SOPRange = Range(ActiveCell, ActiveCell.End(xlDown)).Cells


    'for each person in list �

    For Each SOPCell In SOPRange

        'open a document in Word

        Set doc = wd.Documents.Open(FilePath & "template.doc")

        'go to each bookmark and type in details

        CopyCell "sop", 0
        CopyCell "equipment", 1
        CopyCell "component", 2
        CopyCell "step", 3
        CopyCell "form", 4
        CopyCell "frequency", 5
        CopyCell "frequencyB", 5

        'save and close this document

        doc.SaveAs2 FilePath & "SOP " & SOPCell.Value & ".doc"

        doc.Close

    Next SOPCell

    wd.Quit

    MsgBox "Created files in " & FilePath & "!"

End Sub

Sub CopyCell(BookMarkName As String, ColumnOffset As Integer)

    'copy each cell to relevant Word bookmark

    wd.Selection.GoTo What:=wdGoToBookmark, Name:=BookMarkName

    wd.Selection.TypeText SOPCell.Offset(0, ColumnOffset).Value

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:06:32+00:00Added an answer on June 12, 2026 at 5:06 pm

    You seem to miss the range parameter in your copyCell Sub

    Sub CreateWordDocuments()
    
        'create copy of Word in memory
    
        Dim doc As Word.Document
        wd.Visible = True
        Dim SOPRange As Range
        'create a reference to all the people
    
        Set SOPRange = Range(Range("A1"), Range("A1").End(xlDown)).Cells
    
        'for each person in list 
    
        For Each SOPCell In SOPRange
            'open a document in Word
            Set doc = wd.Documents.Open(FilePath & "template.doc")
            'go to each bookmark and type in details
            CopyCell SOPCell, "sop", 0
            CopyCell SOPCell, "equipment", 1
            CopyCell SOPCell, "component", 2
            CopyCell SOPCell, "step", 3
            CopyCell SOPCell, "form", 4
            CopyCell SOPCell, "frequency", 5
            CopyCell SOPCell, "frequencyB", 5
            'save and close this document
            doc.SaveAs2 FilePath & "SOP " & SOPCell.Value & ".doc"
    
            doc.Close
    
        Next SOPCell
    
        wd.Quit
    
        MsgBox "Created files in " & FilePath & "!"
    
    End Sub
    
    Sub CopyCell(rg As Range, BookMarkName As String, ColumnOffset As Integer)
    
        'copy each cell to relevant Word bookmark
    
        wd.Selection.GoTo What:=wdGoToBookmark, Name:=BookMarkName
    
        wd.Selection.TypeText rg.Offset(0, ColumnOffset).Value
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel VBA macro that creates a folder tree based on an
I have an Excel file with a Macro that connects to an Oracle Database,
I have a simple Excel 2007 Macro that is reading a text file line
I have an Excel macro that is copying all of the information from a
I have a working excel vba macro that does what I want from here
I have an excel template that uses a macro to save the file, so
I have an Excel file that has a bunch of VBA and macro code
I have created a macro for excel which will pop up form that contains
we have several tens of macro enabled excel files, each of those contains few
I have written a VBA macro in an excel spreadsheet that opens all workbooks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.